Fix: folder with the same name should not be created

pull/247/head
HFO4 5 years ago
parent b3ef833afd
commit 0982347f40

@ -1 +1 @@
Subproject commit 341a70e7c8d451fa8c627786434cb5f617fd2f26 Subproject commit 79aaeb9e3a02dab9133f39f872602414b0ab57a0

@ -1,8 +1,10 @@
package middleware package middleware
import ( import (
"github.com/HFO4/cloudreve/pkg/util"
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore" "github.com/gin-contrib/sessions/memstore"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -11,7 +13,10 @@ var Store memstore.Store
// Session 初始化session // Session 初始化session
func Session(secret string) gin.HandlerFunc { func Session(secret string) gin.HandlerFunc {
Store = memstore.NewStore([]byte(secret)) Store, err := redis.NewStore(10, "tcp", "127.0.0.1:6379", "52121225", []byte("secret"))
if err != nil {
util.Log().Panic("无法连接到Redis%s", err)
}
// Also set Secure: true if using SSL, you should though // Also set Secure: true if using SSL, you should though
Store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"}) Store.Options(sessions.Options{HttpOnly: true, MaxAge: 7 * 86400, Path: "/"})
return sessions.Sessions("cloudreve-session", Store) return sessions.Sessions("cloudreve-session", Store)

@ -12,7 +12,8 @@ var (
ErrInsufficientCapacity = errors.New("容量空间不足") ErrInsufficientCapacity = errors.New("容量空间不足")
ErrIllegalObjectName = errors.New("目标名称非法") ErrIllegalObjectName = errors.New("目标名称非法")
ErrInsertFileRecord = serializer.NewError(serializer.CodeDBError, "无法插入文件记录", nil) ErrInsertFileRecord = serializer.NewError(serializer.CodeDBError, "无法插入文件记录", nil)
ErrFileExisted = errors.New("同名文件已存在") ErrFileExisted = serializer.NewError(serializer.CodeObjectExist, "同名文件已存在", nil)
ErrFolderExisted = serializer.NewError(serializer.CodeObjectExist, "同名目录已存在", nil)
ErrPathNotExist = serializer.NewError(404, "路径不存在", nil) ErrPathNotExist = serializer.NewError(404, "路径不存在", nil)
ErrObjectNotExist = serializer.NewError(404, "文件不存在", nil) ErrObjectNotExist = serializer.NewError(404, "文件不存在", nil)
ErrIO = serializer.NewError(serializer.CodeIOFailed, "无法读取文件数据", nil) ErrIO = serializer.NewError(serializer.CodeIOFailed, "无法读取文件数据", nil)

@ -107,6 +107,12 @@ func (fs *FileSystem) CreateDirectory(ctx context.Context, fullPath string) erro
return ErrPathNotExist return ErrPathNotExist
} }
// 是否有同名目录
b, _ := fs.IsPathExist(fullPath)
if b {
return ErrFolderExisted
}
// 是否有同名文件 // 是否有同名文件
if ok, _ := fs.IsFileExist(path.Join(base, dir)); ok { if ok, _ := fs.IsFileExist(path.Join(base, dir)); ok {
return ErrFileExisted return ErrFileExisted

@ -50,6 +50,8 @@ const (
CodeUploadFailed = 40002 CodeUploadFailed = 40002
// CodeCreateFolderFailed 目录创建失败 // CodeCreateFolderFailed 目录创建失败
CodeCreateFolderFailed = 40003 CodeCreateFolderFailed = 40003
// CodeObjectExist 对象已存在
CodeObjectExist = 40004
// CodeDBError 数据库操作失败 // CodeDBError 数据库操作失败
CodeDBError = 50001 CodeDBError = 50001
// CodeEncryptError 加密失败 // CodeEncryptError 加密失败

Loading…
Cancel
Save