From c9c4d6bc7e3066291cc4bb57041d135db13766f7 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sun, 26 Feb 2023 21:25:32 +0800 Subject: [PATCH] fix!(local): perm on mkdir (close #3626) --- drivers/local/driver.go | 15 +++++++++++---- drivers/local/meta.go | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/local/driver.go b/drivers/local/driver.go index 61e6c5d9..fffeec94 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "github.com/alist-org/alist/v3/server/common" "io" "io/ioutil" "net/http" @@ -21,6 +20,7 @@ import ( "github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/sign" "github.com/alist-org/alist/v3/pkg/utils" + "github.com/alist-org/alist/v3/server/common" "github.com/disintegration/imaging" _ "golang.org/x/image/webp" ) @@ -28,6 +28,7 @@ import ( type Local struct { model.Storage Addition + mkdirPerm int32 } func (d *Local) Config() driver.Config { @@ -35,8 +36,14 @@ func (d *Local) Config() driver.Config { } func (d *Local) Init(ctx context.Context) error { - if d.MkdirPerm == 0 { - d.MkdirPerm = 777 + if d.MkdirPerm == "" { + d.mkdirPerm = 0777 + } else { + v, err := strconv.ParseUint(d.MkdirPerm, 8, 32) + if err != nil { + return err + } + d.mkdirPerm = int32(v) } if !utils.Exists(d.GetRootPath()) { return fmt.Errorf("root folder %s not exists", d.GetRootPath()) @@ -168,7 +175,7 @@ func (d *Local) Link(ctx context.Context, file model.Obj, args model.LinkArgs) ( func (d *Local) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error { fullPath := filepath.Join(parentDir.GetPath(), dirName) - err := os.MkdirAll(fullPath, os.FileMode(d.MkdirPerm)) + err := os.MkdirAll(fullPath, os.FileMode(d.mkdirPerm)) if err != nil { return err } diff --git a/drivers/local/meta.go b/drivers/local/meta.go index bdbe9278..efaad4c9 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -9,7 +9,7 @@ type Addition struct { driver.RootPath Thumbnail bool `json:"thumbnail" required:"true" help:"enable thumbnail"` ShowHidden bool `json:"show_hidden" default:"true" required:"false" help:"show hidden directories and files"` - MkdirPerm uint32 `json:"mkdir_perm" type:"number" default:"777"` + MkdirPerm string `json:"mkdir_perm" default:"777"` } var config = driver.Config{