mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: create folder / Modify: add index to some column
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user