mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
fix: create directory now ignore conflict error, it will return the existed folder
This commit is contained in:
@@ -203,14 +203,10 @@ func SlaveAfterUpload(session *serializer.UploadSession) Hook {
|
||||
func GenericAfterUpload(ctx context.Context, fs *FileSystem, fileHeader fsctx.FileHeader) error {
|
||||
fileInfo := fileHeader.Info()
|
||||
|
||||
// 检查路径是否存在,不存在就创建
|
||||
isExist, folder := fs.IsPathExist(fileInfo.VirtualPath)
|
||||
if !isExist {
|
||||
newFolder, err := fs.CreateDirectory(ctx, fileInfo.VirtualPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
folder = newFolder
|
||||
// 创建或查找根目录
|
||||
folder, err := fs.CreateDirectory(ctx, fileInfo.VirtualPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查文件是否存在
|
||||
|
||||
@@ -376,7 +376,8 @@ func (fs *FileSystem) listObjects(ctx context.Context, parent string, files []mo
|
||||
return objects
|
||||
}
|
||||
|
||||
// CreateDirectory 根据给定的完整创建目录,支持递归创建
|
||||
// CreateDirectory 根据给定的完整创建目录,支持递归创建。如果目录已存在,则直接
|
||||
// 返回已存在的目录。
|
||||
func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) (*model.Folder, error) {
|
||||
if fullPath == "/" || fullPath == "." || fullPath == "" {
|
||||
return nil, ErrRootProtected
|
||||
@@ -398,10 +399,6 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) (*mo
|
||||
// 父目录是否存在
|
||||
isExist, parent := fs.IsPathExist(base)
|
||||
if !isExist {
|
||||
// 递归创建父目录
|
||||
if _, ok := ctx.Value(fsctx.IgnoreDirectoryConflictCtx).(bool); !ok {
|
||||
ctx = context.WithValue(ctx, fsctx.IgnoreDirectoryConflictCtx, true)
|
||||
}
|
||||
newParent, err := fs.CreateDirectory(ctx, base)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -424,7 +421,7 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) (*mo
|
||||
|
||||
if err != nil {
|
||||
if _, ok := ctx.Value(fsctx.IgnoreDirectoryConflictCtx).(bool); !ok {
|
||||
return nil, ErrFolderExisted
|
||||
return nil, fmt.Errorf("failed to create folder: %w", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user