mirror of
				https://github.com/cloudreve/cloudreve.git
				synced 2025-11-04 04:47:24 +08:00 
			
		
		
		
	fix: incorrect progress count (#1379)
* fix: incorrect progress count 文件中转 已完成文件计数 应在文件成功上传后+1 #1367 * fix failed ut Co-authored-by: HFO4 <912394456@qq.com>
This commit is contained in:
		@ -96,9 +96,8 @@ func (job *TransferTask) Do() {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for index, file := range job.TaskProps.Src {
 | 
						successCount := 0
 | 
				
			||||||
		job.TaskModel.SetProgress(index)
 | 
						for _, file := range job.TaskProps.Src {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		dst := path.Join(job.TaskProps.Dst, filepath.Base(file))
 | 
							dst := path.Join(job.TaskProps.Dst, filepath.Base(file))
 | 
				
			||||||
		if job.TaskProps.TrimPath {
 | 
							if job.TaskProps.TrimPath {
 | 
				
			||||||
			// 保留原始目录
 | 
								// 保留原始目录
 | 
				
			||||||
@ -132,6 +131,9 @@ func (job *TransferTask) Do() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			job.SetErrorMsg("文件转存失败", err)
 | 
								job.SetErrorMsg("文件转存失败", err)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								successCount++
 | 
				
			||||||
 | 
								job.TaskModel.SetProgress(successCount)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -88,11 +88,6 @@ func TestTransferTask_Do(t *testing.T) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		task.TaskProps.Src = []string{"test/not_exist"}
 | 
							task.TaskProps.Src = []string{"test/not_exist"}
 | 
				
			||||||
		task.TaskProps.Parent = "test/not_exist"
 | 
							task.TaskProps.Parent = "test/not_exist"
 | 
				
			||||||
		// 更新进度
 | 
					 | 
				
			||||||
		mock.ExpectBegin()
 | 
					 | 
				
			||||||
		mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
					 | 
				
			||||||
			1))
 | 
					 | 
				
			||||||
		mock.ExpectCommit()
 | 
					 | 
				
			||||||
		// 更新错误
 | 
							// 更新错误
 | 
				
			||||||
		mock.ExpectBegin()
 | 
							mock.ExpectBegin()
 | 
				
			||||||
		mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
							mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
				
			||||||
@ -113,11 +108,6 @@ func TestTransferTask_Do(t *testing.T) {
 | 
				
			|||||||
		task.TaskProps.Src = []string{"test/not_exist"}
 | 
							task.TaskProps.Src = []string{"test/not_exist"}
 | 
				
			||||||
		task.TaskProps.Parent = "test/not_exist"
 | 
							task.TaskProps.Parent = "test/not_exist"
 | 
				
			||||||
		task.TaskProps.TrimPath = true
 | 
							task.TaskProps.TrimPath = true
 | 
				
			||||||
		// 更新进度
 | 
					 | 
				
			||||||
		mock.ExpectBegin()
 | 
					 | 
				
			||||||
		mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
					 | 
				
			||||||
			1))
 | 
					 | 
				
			||||||
		mock.ExpectCommit()
 | 
					 | 
				
			||||||
		// 更新错误
 | 
							// 更新错误
 | 
				
			||||||
		mock.ExpectBegin()
 | 
							mock.ExpectBegin()
 | 
				
			||||||
		mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
							mock.ExpectExec("UPDATE(.+)").WillReturnResult(sqlmock.NewResult(1,
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user