feat: Allow file and directory creation modes to be configured

The defaults remain the same as before.
For now, the config options are global instead of per-user.
Note also that the BoltDB creation maintains the old default mode of 0640
since it's not really a user-facing filesystem manipulation.
Fixes #5316, #5200
This commit is contained in:
Vincent Lee
2025-07-20 18:21:52 -07:00
committed by Henrique Dias
parent 5b7ea9f95a
commit 21ad653b7e
12 changed files with 73 additions and 41 deletions

View File

@@ -4,9 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/asdine/storm/v3"
@@ -14,12 +16,13 @@ import (
"github.com/spf13/pflag"
yaml "gopkg.in/yaml.v2"
"github.com/filebrowser/filebrowser/v2/files"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/storage"
"github.com/filebrowser/filebrowser/v2/storage/bolt"
)
const dbPerms = 0640
func checkErr(err error) {
if err != nil {
log.Fatal(err)
@@ -32,6 +35,13 @@ func mustGetString(flags *pflag.FlagSet, flag string) string {
return s
}
func mustGetMode(flags *pflag.FlagSet, flag string) fs.FileMode {
s := mustGetString(flags, flag)
b, err := strconv.ParseUint(s, 0, 32)
checkErr(err)
return fs.FileMode(b)
}
func mustGetBool(flags *pflag.FlagSet, flag string) bool {
b, err := flags.GetBool(flag)
checkErr(err)
@@ -106,7 +116,7 @@ func python(fn pythonFunc, cfg pythonConfig) cobraFunc {
log.Println("Using database: " + absPath)
data.hadDB = exists
db, err := storm.Open(path, storm.BoltOptions(files.PermFile, nil))
db, err := storm.Open(path, storm.BoltOptions(dbPerms, nil))
checkErr(err)
defer db.Close()
data.store, err = bolt.NewStorage(db)