fix: invert FindAndOpenSQLiteStore existence check

The condition was backwards — it exited with "database already exists"
when the file was found, and tried to open it when it did not exist.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 01:00:56 +02:00
parent 51341eeb84
commit 2a48ea046b
2 changed files with 6 additions and 11 deletions

View File

@@ -118,10 +118,7 @@ func (s *nodeServiceImpl) getPermContext() (*permContext, error) {
}
for relType, pLevel := range permRelLevels {
for _, tgt := range node.Relations[string(relType)] {
eff := curr.level
if pLevel < eff {
eff = pLevel
}
eff := min(curr.level, pLevel)
if eff > pc.levels[tgt] {
queue = append(queue, entry{tgt, eff})
}

View File

@@ -60,7 +60,7 @@ func InitSQLiteStore(path string) error {
// FindAndOpenSQLiteStore opens the SQLite database. If the AX_DB_PATH environment
// variable is set, it uses that path directly. Otherwise, it walks up from the
// current working directory to find an .ax.db file.
// current working directory to find an .ax/ax.db file.
func FindAndOpenSQLiteStore() (GraphStore, error) {
if dbpath := os.Getenv("AX_DB_PATH"); dbpath != "" {
return NewSQLiteStore(dbpath)
@@ -68,13 +68,11 @@ func FindAndOpenSQLiteStore() (GraphStore, error) {
dataRoot, err := FindDataRoot(".local", "share")
if err != nil {
fmt.Fprintln(os.Stderr, "failed to find data dir:", err)
os.Exit(1)
return nil, fmt.Errorf("failed to find data dir: %w", err)
}
dbPath := filepath.Join(dataRoot, "ax.db")
if _, err := os.Stat(dbPath); err == nil {
fmt.Fprintln(os.Stderr, "database already exists:", dbPath)
os.Exit(1)
if _, err := os.Stat(dbPath); err != nil {
return nil, fmt.Errorf("no database found at %s: run 'ax init' first", dbPath)
}
return NewSQLiteStore(dbPath)
}