diff --git a/cmd/config_init.go b/cmd/config_init.go index cc85f601..f0eb83df 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -52,12 +52,12 @@ override the options.`, }, } - s.FileMode, err = getAndParseMode(v, "filemode") + s.FileMode, err = parseFileMode(v.GetString("fileMode")) if err != nil { return err } - s.DirMode, err = getAndParseMode(v, "dirmode") + s.DirMode, err = parseFileMode(v.GetString("dirMode")) if err != nil { return err } diff --git a/cmd/config_set.go b/cmd/config_set.go index 300cf136..41f4f757 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -78,9 +78,9 @@ you want to change. Other options will remain unchanged.`, case "branding.files": set.Branding.Files = v.GetString(key) case "filemode": - set.FileMode, err = getAndParseMode(v, key) + set.FileMode, err = parseFileMode(v.GetString(key)) case "dirmode": - set.DirMode, err = getAndParseMode(v, key) + set.DirMode, err = parseFileMode(v.GetString(key)) } if err != nil { diff --git a/cmd/utils.go b/cmd/utils.go index 0712b2d2..5c6b5870 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -24,11 +24,10 @@ import ( "github.com/filebrowser/filebrowser/v2/storage/bolt" ) -const dbPerms = 0640 +const databasePermissions = 0640 -func getAndParseMode(v *viper.Viper, param string) (fs.FileMode, error) { - s := v.GetString(param) - b, err := strconv.ParseUint(s, 0, 32) +func parseFileMode(value string) (fs.FileMode, error) { + b, err := strconv.ParseUint(value, 0, 32) if err != nil { return 0, err } @@ -43,20 +42,6 @@ func generateKey() []byte { return k } -type cobraFunc func(cmd *cobra.Command, args []string) error -type pythonFunc func(cmd *cobra.Command, args []string, v *viper.Viper, data *pythonData) error - -type pythonConfig struct { - noDB bool - allowNoDB bool -} - -type pythonData struct { - hadDB bool - store *storage.Storage - err error -} - func dbExists(path string) (bool, error) { stat, err := os.Stat(path) if err == nil { @@ -79,7 +64,7 @@ func dbExists(path string) (bool, error) { // Generate the replacements for all environment variables. This allows to // use FB_BRANDING_DISABLE_EXTERNAL environment variables, even when the -// option name is branding.disableexternal. +// option name is branding.disableExternal. func generateEnvKeyReplacements(cmd *cobra.Command) []string { replacements := []string{} @@ -141,6 +126,20 @@ func initViper(cmd *cobra.Command) (*viper.Viper, error) { return v, nil } +type cobraFunc func(cmd *cobra.Command, args []string) error +type pythonFunc func(cmd *cobra.Command, args []string, v *viper.Viper, data *pythonData) error + +type pythonConfig struct { + noDB bool + allowNoDB bool +} + +type pythonData struct { + hadDB bool + store *storage.Storage + err error +} + func python(fn pythonFunc, cfg pythonConfig) cobraFunc { return func(cmd *cobra.Command, args []string) error { v, err := initViper(cmd) @@ -169,7 +168,7 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc { log.Println("Using database: " + absPath) data.hadDB = exists - db, err := storm.Open(path, storm.BoltOptions(dbPerms, nil)) + db, err := storm.Open(path, storm.BoltOptions(databasePermissions, nil)) if err != nil { return err }