fix(fs):Repair file loss caused by special reasons when moving files (#321)

* fix(move):Fix file move logic

* fix(move):fixed move logic
This commit is contained in:
Suyunjing
2025-06-23 19:48:17 +08:00
committed by GitHub
parent b0736d2d02
commit 96cf2f7cf9

View File

@ -128,14 +128,10 @@ func moveFileBetween2Storages(tsk *MoveTask, srcStorage, dstStorage driver.Drive
SrcStorageMp: srcStorage.GetStorage().MountPath,
DstStorageMp: dstStorage.GetStorage().MountPath,
}
copyTask.SetCtx(tsk.Ctx())
err := copyBetween2Storages(copyTask, srcStorage, dstStorage, srcFilePath, dstDirPath)
if err != nil {
// Check if this is an upload-related error and provide a clearer message
if errors.Is(err, errs.UploadNotSupported) {
return errors.WithMessagef(err, "destination storage [%s] does not support file uploads", dstStorage.GetStorage().MountPath)
}
@ -143,6 +139,23 @@ func moveFileBetween2Storages(tsk *MoveTask, srcStorage, dstStorage driver.Drive
}
tsk.SetProgress(50)
tsk.Status = "verifying file in destination"
// check target files
dstFilePath := stdpath.Join(dstDirPath, stdpath.Base(srcFilePath))
const maxRetries = 3
const retryInterval = time.Second
var checkErr error
for i := 0; i < maxRetries; i++ {
_, checkErr = op.Get(tsk.Ctx(), dstStorage, dstFilePath)
if checkErr == nil {
break
}
time.Sleep(retryInterval)
}
if checkErr != nil {
return errors.WithMessagef(checkErr, "file not found in destination [%s] after copy", dstFilePath)
}
tsk.Status = "deleting source file"
err = op.Remove(tsk.Ctx(), srcStorage, srcFilePath)
@ -155,7 +168,6 @@ func moveFileBetween2Storages(tsk *MoveTask, srcStorage, dstStorage driver.Drive
return nil
}
func _move(ctx context.Context, srcObjPath, dstDirPath string, lazyCache ...bool) (task.TaskExtensionInfo, error) {
srcStorage, srcObjActualPath, err := op.GetStorageAndActualPath(srcObjPath)
if err != nil {