Skip to content

Commit 6c12c49

Browse files
committed
fix: statDirIfExist
1 parent 93519bc commit 6c12c49

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

modules/options/base.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,18 @@ func walkAssetDir(root string, callback func(path, name string, d fs.DirEntry, e
7878
}
7979
return nil
8080
}
81+
82+
func statDirIfExist(dir string) ([]string, error) {
83+
isDir, err := util.IsDir(dir)
84+
if err != nil {
85+
return nil, fmt.Errorf("unable to check if static directory %s is a directory. %w", dir, err)
86+
}
87+
if !isDir {
88+
return nil, nil
89+
}
90+
files, err := util.StatDir(dir, true)
91+
if err != nil {
92+
return nil, fmt.Errorf("unable to read directory %q. %w", dir, err)
93+
}
94+
return files, nil
95+
}

modules/options/dynamic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func Dir(name string) ([]string, error) {
2929
path.Join(setting.CustomPath, "options", name), // custom dir
3030
path.Join(setting.StaticRootPath, "options", name), // static dir
3131
} {
32-
files, err := util.StatDir(dir, true)
32+
files, err := statDirIfExist(dir)
3333
if err != nil {
34-
return nil, fmt.Errorf("unable to read directory %q. %w", dir, err)
34+
return nil, err
3535
}
3636
result = append(result, files...)
3737
}

modules/options/static.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func Dir(name string) ([]string, error) {
3030
path.Join(setting.CustomPath, "options", name), // custom dir
3131
// no static dir
3232
} {
33-
files, err := util.StatDir(dir, true)
33+
files, err := statDirIfExist(dir)
3434
if err != nil {
35-
return nil, fmt.Errorf("unable to read directory %q. %w", dir, err)
35+
return nil, err
3636
}
3737
result = append(result, files...)
3838
}

0 commit comments

Comments
 (0)