mirror of
https://github.com/gin-gonic/gin.git
synced 2025-04-06 03:57:46 +08:00
refactor(context):Avoid using filepath.Dir twice in SaveUploadedFile (#4181)
Co-authored-by: voyager1 <voyager1@voyager1deMacBook-Pro.local>
This commit is contained in:
parent
1eb827240e
commit
a4baac6e5e
12
context.go
12
context.go
@ -684,15 +684,15 @@ func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
if len(perm) <= 0 {
|
||||
perm = append(perm, 0o750)
|
||||
var mode os.FileMode = 0o750
|
||||
if len(perm) > 0 {
|
||||
mode = perm[0]
|
||||
}
|
||||
|
||||
if err = os.MkdirAll(filepath.Dir(dst), perm[0]); err != nil {
|
||||
dir := filepath.Dir(dst)
|
||||
if err = os.MkdirAll(dir, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = os.Chmod(filepath.Dir(dst), perm[0]); err != nil {
|
||||
if err = os.Chmod(dir, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user