feat: optimize dfpath format (#2460)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2023-06-14 11:58:10 +08:00
parent 8c905d9b8d
commit 8b7ceb60b5
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
3 changed files with 6 additions and 3 deletions

View File

@ -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)))
}

View File

@ -19,6 +19,7 @@
package dfpath
import (
"os"
"path/filepath"
"d7y.io/dragonfly/v2/pkg/os/user"

View File

@ -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)