Feat: create folder / Modify: add index to some column

This commit is contained in:
HFO4
2019-11-24 11:33:30 +08:00
parent 89b54e401c
commit a89c3cb11a
7 changed files with 112 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package filesystem
import (
"context"
model "github.com/HFO4/cloudreve/models"
"path"
)
@@ -10,6 +11,42 @@ import (
=================
*/
// CreateDirectory 在`base`路径下创建名为`dir`的目录
func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) error {
// 获取要创建目录的父路径和目录名
fullPath = path.Clean(fullPath)
base := path.Dir(fullPath)
dir := path.Base(fullPath)
// 检查目录名是否合法
if !fs.ValidateLegalName(ctx, dir) {
return ErrIllegalObjectName
}
// 父目录是否存在
isExist, parent := fs.IsPathExist(base)
if !isExist {
return ErrPathNotExist
}
// 是否有同名文件
if fs.IsFileExist(path.Join(base, dir)) {
return ErrFileExisted
}
// 创建目录
newFolder := model.Folder{
Name: dir,
ParentID: parent.ID,
Position: base,
OwnerID: fs.User.ID,
PositionAbsolute: fullPath,
}
_, err := newFolder.Create()
return err
}
// IsPathExist 返回给定目录是否存在
// 如果存在就返回目录
func (fs *FileSystem) IsPathExist(path string) (bool, *model.Folder) {

View File

@@ -21,6 +21,8 @@ const (
CodeNoRightErr = 403
// CodeUploadFailed 上传出错
CodeUploadFailed = 4001
// CodeCreateFolderFailed 目录创建失败
CodeCreateFolderFailed = 4002
// CodeDBError 数据库操作失败
CodeDBError = 50001
// CodeEncryptError 加密失败