fix: use FindDataRoot in FindOrInitSQLiteStore for consistent database location
Some checks failed
Build and Publish APK Package / build-apk (arm64, aarch64) (push) Has been cancelled
Build and Publish APK Package / build-apk (amd64, x86_64) (push) Has been cancelled
Build and Push Docker Container / build-and-push (push) Successful in 17m44s
Build and Publish Arch Package / build-arch (amd64, x86_64) (push) Failing after 58s
Build and Publish Arch Package / build-arch (arm64, aarch64) (push) Failing after 1m0s

This commit is contained in:
2026-04-02 14:26:13 +02:00
parent e04a44cdcf
commit 2c48c75387

View File

@@ -74,31 +74,20 @@ func FindAndOpenSQLiteStore() (GraphStore, error) {
} }
// FindOrInitSQLiteStore is like FindAndOpenSQLiteStore but intended for server // FindOrInitSQLiteStore is like FindAndOpenSQLiteStore but intended for server
// mode: if no .ax.db is found it creates and initialises one in the current // mode: if no database is found it creates and initialises one in the
// working directory instead of returning an error. // ~/.local/share/ax/ directory instead of returning an error.
func FindOrInitSQLiteStore() (GraphStore, error) { func FindOrInitSQLiteStore() (GraphStore, error) {
dir, err := filepath.Abs(".") dataRoot, err := FindDataRoot(".local", "share")
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to find data dir: %w", err)
} }
for { dbPath := filepath.Join(dataRoot, "ax.db")
dbpath := filepath.Join(dir, ".ax.db") if _, err := os.Stat(dbPath); err != nil {
if _, err := os.Stat(dbpath); err == nil { if err := InitSQLiteStore(dbPath); err != nil {
return NewSQLiteStore(dbpath) return nil, err
}
if parent := filepath.Dir(dir); parent == dir {
break
} else {
dir = parent
} }
} }
// Not found — create and initialise in CWD. return NewSQLiteStore(dbPath)
cwd, _ := filepath.Abs(".")
dbpath := filepath.Join(cwd, ".ax.db")
if err := InitSQLiteStore(dbpath); err != nil {
return nil, err
}
return NewSQLiteStore(dbpath)
} }
// NewSQLiteStore opens a SQLite database at the given path, runs a one-time // NewSQLiteStore opens a SQLite database at the given path, runs a one-time