From 8b7ceb60b51b7bc7455af7c3bd26d1023c5bcac6 Mon Sep 17 00:00:00 2001 From: Gaius Date: Wed, 14 Jun 2023 11:58:10 +0800 Subject: [PATCH] feat: optimize dfpath format (#2460) Signed-off-by: Gaius --- cmd/dfget/cmd/daemon.go | 2 ++ pkg/dfpath/dfpath_darwin.go | 1 + pkg/dfpath/dfpath_test.go | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/dfget/cmd/daemon.go b/cmd/dfget/cmd/daemon.go index 0f0e0b2ab..feaf55fe8 100644 --- a/cmd/dfget/cmd/daemon.go +++ b/cmd/dfget/cmd/daemon.go @@ -103,6 +103,7 @@ func initDaemonDfpath(cfg *config.DaemonOption) (dfpath.Dfpath, error) { if cfg.WorkHome != "" { options = append(options, dfpath.WithWorkHome(cfg.WorkHome)) } + if os.FileMode(cfg.WorkHomeMode) != os.FileMode(0) { options = append(options, dfpath.WithWorkHomeMode(os.FileMode(cfg.WorkHomeMode))) } @@ -110,6 +111,7 @@ func initDaemonDfpath(cfg *config.DaemonOption) (dfpath.Dfpath, error) { if cfg.CacheDir != "" { options = append(options, dfpath.WithCacheDir(cfg.CacheDir)) } + if os.FileMode(cfg.CacheDirMode) != os.FileMode(0) { options = append(options, dfpath.WithCacheDirMode(os.FileMode(cfg.CacheDirMode))) } diff --git a/pkg/dfpath/dfpath_darwin.go b/pkg/dfpath/dfpath_darwin.go index 4a9aa33e7..ff1549fa7 100644 --- a/pkg/dfpath/dfpath_darwin.go +++ b/pkg/dfpath/dfpath_darwin.go @@ -19,6 +19,7 @@ package dfpath import ( + "os" "path/filepath" "d7y.io/dragonfly/v2/pkg/os/user" diff --git a/pkg/dfpath/dfpath_test.go b/pkg/dfpath/dfpath_test.go index a9648c42d..5969ffcd7 100644 --- a/pkg/dfpath/dfpath_test.go +++ b/pkg/dfpath/dfpath_test.go @@ -59,7 +59,7 @@ func TestNew(t *testing.T) { }, }, { - name: "new dfpath by workHome", + name: "new dfpath by workHome and workHomeMode", options: []Option{WithWorkHome("foo"), WithWorkHomeMode(os.FileMode(0700))}, expect: func(t *testing.T, options []Option) { assert := assert.New(t) @@ -77,7 +77,7 @@ func TestNew(t *testing.T) { }, }, { - name: "new dfpath by cacheDir", + name: "new dfpath by cacheDir and cacheDirMode", options: []Option{WithCacheDir("foo"), WithCacheDirMode(os.FileMode(0700))}, expect: func(t *testing.T, options []Option) { assert := assert.New(t) @@ -113,7 +113,7 @@ func TestNew(t *testing.T) { }, }, { - name: "new dfpath by dataDir", + name: "new dfpath by dataDir and dataDirMode", options: []Option{WithDataDir("foo"), WithDataDirMode(os.FileMode(0700))}, expect: func(t *testing.T, options []Option) { assert := assert.New(t)