db config: don't exit setup if can't detect fs, improve detection for freebsd (#2963)

This commit is contained in:
mmetc 2024-04-25 11:11:57 +02:00 committed by GitHub
parent 0f942a95f1
commit 60431804d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 10 deletions

View file

@ -76,26 +76,24 @@ func (c *Config) LoadDBConfig(inCli bool) error {
if c.DbConfig.UseWal == nil { if c.DbConfig.UseWal == nil {
dbDir := filepath.Dir(c.DbConfig.DbPath) dbDir := filepath.Dir(c.DbConfig.DbPath)
isNetwork, fsType, err := types.IsNetworkFS(dbDir) 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.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.") 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 case isNetwork:
}
if isNetwork {
log.Debugf("database is on network filesystem (%s), setting useWal to false", fsType) log.Debugf("database is on network filesystem (%s), setting useWal to false", fsType)
c.DbConfig.UseWal = ptr.Of(false) c.DbConfig.UseWal = ptr.Of(false)
} else { default:
log.Debugf("database is on local filesystem (%s), setting useWal to true", fsType) log.Debugf("database is on local filesystem (%s), setting useWal to true", fsType)
c.DbConfig.UseWal = ptr.Of(true) c.DbConfig.UseWal = ptr.Of(true)
} }
} else if *c.DbConfig.UseWal { } else if *c.DbConfig.UseWal {
dbDir := filepath.Dir(c.DbConfig.DbPath) dbDir := filepath.Dir(c.DbConfig.DbPath)
isNetwork, fsType, err := types.IsNetworkFS(dbDir) 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.Warnf("unable to determine if database is on network filesystem: %s", err)
return nil case isNetwork:
}
if 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) log.Warnf("database seems to be stored on a network share (%s), but useWal is set to true. Proceed at your own risk.", fsType)
} }
} }

View file

@ -1,4 +1,4 @@
//go:build !windows //go:build !windows && !freebsd
package types package types

View file

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