← Back to task

Commit 8fe76d64

commit 8fe76d644e1d3447fe2606b6d24a3dbdd222c108
Author: Coder Agent <coder@agents.omni>
Date:   Mon Feb 16 20:40:17 2026

    Use XDG path default for Newsreader DB
    
    When NEWSREADER_DB_PATH is unset, default to XDG data:
    
    ~/.local/share/omni/newsreader.db (or XDG_DATA_HOME/omni/newsreader.db).
    
    Task-Id: t-618

diff --git a/Omni/Newsreader/Db.hs b/Omni/Newsreader/Db.hs
index e1444d47..dcc766b1 100644
--- a/Omni/Newsreader/Db.hs
+++ b/Omni/Newsreader/Db.hs
@@ -27,23 +27,28 @@ import Alpha
 import Data.String (fromString)
 import qualified Data.Text as T
 import qualified Database.SQLite.Simple as SQL
-import System.Directory (createDirectoryIfMissing)
+import qualified System.Directory as Directory
 import System.Environment (lookupEnv)
-import System.FilePath (takeDirectory)
+import System.FilePath (takeDirectory, (</>))
 
 -- | Get the newsreader database path from environment or use default.
--- Checks NEWSREADER_DB_PATH env var, falls back to _/tmp/newsreader.db
+-- Priority: NEWSREADER_DB_PATH env var > $XDG_DATA_HOME/omni/newsreader.db
+-- XDG_DATA_HOME defaults to ~/.local/share per the XDG Base Directory spec.
 getDbPath :: IO FilePath
 getDbPath = do
   maybeDbPath <- lookupEnv "NEWSREADER_DB_PATH"
-  pure <| fromMaybe "_/tmp/newsreader.db" maybeDbPath
+  case maybeDbPath of
+    Just p -> pure p
+    Nothing -> do
+      dataDir <- Directory.getXdgDirectory Directory.XdgData "omni"
+      pure (dataDir </> "newsreader.db")
 
 -- | Execute an action with a database connection.
 -- Ensures connection is properly closed after use.
 withDb :: (SQL.Connection -> IO a) -> IO a
 withDb action = do
   dbPath <- getDbPath
-  createDirectoryIfMissing True (takeDirectory dbPath)
+  Directory.createDirectoryIfMissing True (takeDirectory dbPath)
   SQL.withConnection dbPath action
 
 -- | Initialize database with schema.
@@ -52,7 +57,7 @@ initDb :: IO ()
 initDb = do
   dbPath <- getDbPath
   putText <| "Initializing newsreader database at: " <> T.pack dbPath
-  createDirectoryIfMissing True (takeDirectory dbPath)
+  Directory.createDirectoryIfMissing True (takeDirectory dbPath)
   withDb <| \conn -> do
     initSchema conn
     putText "Database initialized successfully"