From 60431804d8440b68e7c253be8f44137c832bf4b4 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:11:57 +0200 Subject: [PATCH] db config: don't exit setup if can't detect fs, improve detection for freebsd (#2963) --- pkg/csconfig/database.go | 16 +++++++--------- pkg/types/getfstype.go | 2 +- pkg/types/getfstype_freebsd.go | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 pkg/types/getfstype_freebsd.go diff --git a/pkg/csconfig/database.go b/pkg/csconfig/database.go index a7bc57eef..9a9ed9a9f 100644 --- a/pkg/csconfig/database.go +++ b/pkg/csconfig/database.go @@ -76,26 +76,24 @@ func (c *Config) LoadDBConfig(inCli bool) error { if c.DbConfig.UseWal == nil { dbDir := filepath.Dir(c.DbConfig.DbPath) isNetwork, fsType, err := types.IsNetworkFS(dbDir) - if err != nil { + switch { + case err != nil: log.Warnf("unable to determine if database is on network filesystem: %s", err) log.Warning("You are using sqlite without WAL, this can have a performance impact. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.") - return nil - } - if isNetwork { + case isNetwork: log.Debugf("database is on network filesystem (%s), setting useWal to false", fsType) c.DbConfig.UseWal = ptr.Of(false) - } else { + default: log.Debugf("database is on local filesystem (%s), setting useWal to true", fsType) c.DbConfig.UseWal = ptr.Of(true) } } else if *c.DbConfig.UseWal { dbDir := filepath.Dir(c.DbConfig.DbPath) isNetwork, fsType, err := types.IsNetworkFS(dbDir) - if err != nil { + switch { + case err != nil: log.Warnf("unable to determine if database is on network filesystem: %s", err) - return nil - } - if isNetwork { + case isNetwork: log.Warnf("database seems to be stored on a network share (%s), but useWal is set to true. Proceed at your own risk.", fsType) } } diff --git a/pkg/types/getfstype.go b/pkg/types/getfstype.go index 67e018782..25790ecb6 100644 --- a/pkg/types/getfstype.go +++ b/pkg/types/getfstype.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build !windows && !freebsd package types diff --git a/pkg/types/getfstype_freebsd.go b/pkg/types/getfstype_freebsd.go new file mode 100644 index 000000000..8fbe3dd7c --- /dev/null +++ b/pkg/types/getfstype_freebsd.go @@ -0,0 +1,25 @@ +//go:build freebsd + +package types + +import ( + "fmt" + "syscall" +) + +func GetFSType(path string) (string, error) { + var fsStat syscall.Statfs_t + + if err := syscall.Statfs(path, &fsStat); err != nil { + return "", fmt.Errorf("failed to get filesystem type: %w", err) + } + + bs := fsStat.Fstypename + + b := make([]byte, len(bs)) + for i, v := range bs { + b[i] = byte(v) + } + + return string(b), nil +}