|
|
@ -38,26 +38,32 @@ func moveFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
|
|
|
fileIDs = []uint{src.(*model.File).ID}
|
|
|
|
fileIDs = []uint{src.(*model.File).ID}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否需要移动
|
|
|
|
if overwrite {
|
|
|
|
if src.GetPosition() != path.Dir(dst) {
|
|
|
|
if err := _checkOverwriteFile(ctx, fs, src, dst); err != nil {
|
|
|
|
err = fs.Move(
|
|
|
|
return http.StatusInternalServerError, err
|
|
|
|
ctx,
|
|
|
|
}
|
|
|
|
folderIDs,
|
|
|
|
}
|
|
|
|
fileIDs,
|
|
|
|
|
|
|
|
src.GetPosition(),
|
|
|
|
// 判断是否需要移动
|
|
|
|
path.Dir(dst),
|
|
|
|
if src.GetPosition() != path.Dir(dst) {
|
|
|
|
)
|
|
|
|
err = fs.Move(
|
|
|
|
}
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
folderIDs,
|
|
|
|
// 判断是否需要重命名
|
|
|
|
fileIDs,
|
|
|
|
if err == nil && src.GetName() != path.Base(dst) {
|
|
|
|
src.GetPosition(),
|
|
|
|
err = fs.Rename(
|
|
|
|
path.Dir(dst),
|
|
|
|
ctx,
|
|
|
|
)
|
|
|
|
folderIDs,
|
|
|
|
}
|
|
|
|
fileIDs,
|
|
|
|
|
|
|
|
path.Base(dst),
|
|
|
|
// 判断是否需要重命名
|
|
|
|
)
|
|
|
|
if err == nil && src.GetName() != path.Base(dst) {
|
|
|
|
}
|
|
|
|
err = fs.Rename(
|
|
|
|
|
|
|
|
ctx,
|
|
|
|
|
|
|
|
folderIDs,
|
|
|
|
|
|
|
|
fileIDs,
|
|
|
|
|
|
|
|
path.Base(dst),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return http.StatusInternalServerError, err
|
|
|
|
return http.StatusInternalServerError, err
|
|
|
@ -74,6 +80,12 @@ func copyFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recursion++
|
|
|
|
recursion++
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if overwrite {
|
|
|
|
|
|
|
|
if err := _checkOverwriteFile(ctx, fs, src, dst); err != nil {
|
|
|
|
|
|
|
|
return http.StatusInternalServerError, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if src.IsDir() {
|
|
|
|
if src.IsDir() {
|
|
|
|
err := fs.Copy(
|
|
|
|
err := fs.Copy(
|
|
|
|
ctx,
|
|
|
|
ctx,
|
|
|
@ -94,6 +106,22 @@ func copyFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
|
|
|
return http.StatusNoContent, nil
|
|
|
|
return http.StatusNoContent, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断目标 文件/夹 是否已经存在,存在则先删除目标文件/夹
|
|
|
|
|
|
|
|
func _checkOverwriteFile(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst string) error {
|
|
|
|
|
|
|
|
if src.IsDir() {
|
|
|
|
|
|
|
|
ok, folder := fs.IsPathExist(dst)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
|
|
return fs.Delete(ctx, []uint{folder.ID}, []uint{}, false, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ok, file := fs.IsFileExist(dst)
|
|
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
|
|
return fs.Delete(ctx, []uint{}, []uint{file.ID}, false, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// walkFS traverses filesystem fs starting at name up to depth levels.
|
|
|
|
// walkFS traverses filesystem fs starting at name up to depth levels.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Allowed values for depth are 0, 1 or infiniteDepth. For each visited node,
|
|
|
|
// Allowed values for depth are 0, 1 or infiniteDepth. For each visited node,
|
|
|
|