Consolidate the data directory mode into one owner (closes #288)
check / check (push) Failing after 1s
check / check (push) Failing after 1s
internal/datadir now owns the DATA_DIR mode as an exported constant, DirPerm; internal/database consumes it in both places that create the directory rather than keeping its own copy. datadir is the owner because guarding and creating DATA_DIR is its whole purpose, and the dependency runs the right way: datadir imports only the standard library and the flock package, so database importing datadir adds no cycle. A comment on DirPerm names it as the single source, chosen over a source-scanning test because it survives refactoring and builds no machinery that inspects the tree. The mode value is unchanged. Model: opus-4-8
This commit is contained in:
@@ -17,12 +17,12 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"sneak.berlin/go/webhooker/internal/banner"
|
||||
"sneak.berlin/go/webhooker/internal/config"
|
||||
"sneak.berlin/go/webhooker/internal/datadir"
|
||||
"sneak.berlin/go/webhooker/internal/gormlog"
|
||||
"sneak.berlin/go/webhooker/internal/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
dataDirPerm = 0750
|
||||
randomPasswordLen = 16
|
||||
sessionKeyLen = 32
|
||||
)
|
||||
@@ -185,7 +185,9 @@ func (d *Database) connect() error {
|
||||
// caller's decision.
|
||||
func (d *Database) connectTo(dataDir string) error {
|
||||
// Ensure the data directory exists before opening the database.
|
||||
err := os.MkdirAll(dataDir, dataDirPerm)
|
||||
// datadir.DirPerm is the single source of the directory mode; this
|
||||
// package creates the directory too, since either may run first.
|
||||
err := os.MkdirAll(dataDir, datadir.DirPerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"creating data directory %s: %w",
|
||||
|
||||
Reference in New Issue
Block a user