fix: 解决文件上传权限错误的问题 (#4563)

pull/4569/head
zhengkunwang 2024-04-18 11:18:07 +08:00 committed by GitHub
parent ef5a13f87f
commit 4832081b82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -596,7 +596,7 @@ func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int)
dstDir = strings.TrimSpace(dstDir)
mode, _ := files.GetParentMode(dstDir)
if mode == 0 {
mode = os.ModePerm
mode = 0755
}
if _, err := os.Stat(dstDir); err != nil && os.IsNotExist(err) {
if err = op.CreateDir(dstDir, mode); err != nil {

View File

@ -57,7 +57,14 @@ func (f FileOp) CreateDir(dst string, mode fs.FileMode) error {
if err := f.Fs.MkdirAll(dst, mode); err != nil {
return err
}
return f.ChmodR(dst, int64(mode), true)
modStr := fmt.Sprintf("%o", mode)
modeInt, err := strconv.ParseInt(modStr, 10, 64)
if err != nil {
modeInt = 0755
}
return f.ChmodR(dst, modeInt, true)
}
func (f FileOp) CreateFile(dst string) error {

View File

@ -129,7 +129,7 @@ func GetParentMode(path string) (os.FileMode, error) {
for {
fileInfo, err := os.Stat(absPath)
if err == nil {
return fileInfo.Mode(), nil
return fileInfo.Mode() & os.ModePerm, nil
}
if !os.IsNotExist(err) {
return 0, err