don't store database file in home directory

Instead of being stored in ~/.passman.json, it will be stored in
~/.passman/database.json on *NIX and as database.json in the app data
directory on Windows
This commit is contained in:
Jonathan Lamothe 2020-03-20 17:24:14 -04:00
parent 645142aa8f
commit ef663b39b0

View File

@ -24,9 +24,12 @@ module Main where
import Control.Monad (mapM_)
import Control.Monad.Trans.State as S
import Data.Maybe (maybe)
import System.Console.HCL (Request, reqFail, reqIO, runRequest)
import System.Environment (lookupEnv)
import System.Console.HCL (Request, reqIO, runRequest)
import System.EasyFile
( createDirectoryIfMissing
, getAppUserDataDirectory
, (</>)
)
import System.Random (getStdGen)
import Types
@ -45,24 +48,9 @@ setup = do
return $ Status g pw p db
getDBPath :: Request FilePath
getDBPath = reqIO (lookupEnv "HOME") >>= maybe
(do
reqIO $ putStrLn "ERROR: can't find home directory"
reqFail)
(\home -> case pathDelim home of
Nothing -> do
reqIO $ putStrLn "ERROR: unsupported home path"
reqFail
Just delim -> return $ home ++
(if last home == delim then "" else [delim]) ++
".passman.json")
pathDelim :: FilePath -> Maybe Char
pathDelim = foldr
(\x a -> case x of
'/' -> Just '/'
'\\' -> Just '\\'
_ -> a)
Nothing
getDBPath = reqIO $ do
path <- getAppUserDataDirectory "passman"
createDirectoryIfMissing True path
return $ path </> "database.json"
--jl