feat: 解决创建软连接失败的BUG

This commit is contained in:
zhengkunwang223 2023-03-10 16:01:36 +08:00 committed by zhengkunwang223
parent b27f42df58
commit bb9c2490c4
6 changed files with 13 additions and 7 deletions

View File

@ -20,7 +20,7 @@ type FileCreate struct {
IsDir bool `json:"isDir"`
Mode int64 `json:"mode" validate:"required"`
IsLink bool `json:"isLink"`
IsSymlink bool `json:"isSymlink "`
IsSymlink bool `json:"isSymlink"`
LinkPath string `json:"linkPath"`
}

View File

@ -93,12 +93,15 @@ func (f FileService) GetFileTree(op request.FileOption) ([]response.FileTree, er
func (f FileService) Create(op request.FileCreate) error {
fo := files.NewFileOp()
if fo.Stat(op.Path) {
return errors.New("file is exist")
return buserr.New(constant.ErrFileIsExit)
}
if op.IsDir {
return fo.CreateDir(op.Path, fs.FileMode(op.Mode))
} else {
if op.IsLink {
if !fo.Stat(op.Path) {
return buserr.New(constant.ErrLinkPathNotFound)
}
return fo.LinkFile(op.LinkPath, op.Path, op.IsSymlink)
} else {
return fo.CreateFile(op.Path)

View File

@ -79,8 +79,10 @@ var (
//file
var (
ErrPathNotFound = "ErrPathNotFound"
ErrMovePathFailed = "ErrMovePathFailed"
ErrPathNotFound = "ErrPathNotFound"
ErrMovePathFailed = "ErrMovePathFailed"
ErrLinkPathNotFound = "ErrLinkPathNotFound"
ErrFileIsExit = "ErrFileIsExit"
)
//mysql

View File

@ -32,6 +32,8 @@ ErrFileCanNotRead: "File can not read"
ErrFileToLarge: "file is too large"
ErrPathNotFound: "Path is not found"
ErrMovePathFailed: "The target path cannot contain the original path!"
ErrLinkPathNotFound: "Target path does not exist!"
ErrFileIsExit: "File already exists!"
#website
ErrDomainIsExist: "Domain is already exist"

View File

@ -32,6 +32,8 @@ ErrFileCanNotRead: "此文件不支持预览"
ErrFileToLarge: "文件超过10M,无法打开"
ErrPathNotFound: "目录不存在"
ErrMovePathFailed: "目标路径不能包含原路径!"
ErrLinkPathNotFound: "目标路径不存在!"
ErrFileIsExit: "文件已存在!"
#website
ErrDomainIsExist: "域名已存在"

View File

@ -151,7 +151,6 @@ func (w *WriteCounter) SaveProcess() {
global.LOG.Errorf("save cache error, err %s", err.Error())
}
}
}
func (f FileOp) DownloadFileWithProcess(url, dst, key string) error {
@ -183,7 +182,6 @@ func (f FileOp) DownloadFileWithProcess(url, dst, key string) error {
out.Close()
resp.Body.Close()
}()
return nil
}
@ -205,7 +203,6 @@ func (f FileOp) DownloadFile(url, dst string) error {
}
out.Close()
resp.Body.Close()
return nil
}