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:
parent
645142aa8f
commit
ef663b39b0
32
app/Main.hs
32
app/Main.hs
|
@ -24,9 +24,12 @@ module Main where
|
||||||
|
|
||||||
import Control.Monad (mapM_)
|
import Control.Monad (mapM_)
|
||||||
import Control.Monad.Trans.State as S
|
import Control.Monad.Trans.State as S
|
||||||
import Data.Maybe (maybe)
|
import System.Console.HCL (Request, reqIO, runRequest)
|
||||||
import System.Console.HCL (Request, reqFail, reqIO, runRequest)
|
import System.EasyFile
|
||||||
import System.Environment (lookupEnv)
|
( createDirectoryIfMissing
|
||||||
|
, getAppUserDataDirectory
|
||||||
|
, (</>)
|
||||||
|
)
|
||||||
import System.Random (getStdGen)
|
import System.Random (getStdGen)
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
|
@ -45,24 +48,9 @@ setup = do
|
||||||
return $ Status g pw p db
|
return $ Status g pw p db
|
||||||
|
|
||||||
getDBPath :: Request FilePath
|
getDBPath :: Request FilePath
|
||||||
getDBPath = reqIO (lookupEnv "HOME") >>= maybe
|
getDBPath = reqIO $ do
|
||||||
(do
|
path <- getAppUserDataDirectory "passman"
|
||||||
reqIO $ putStrLn "ERROR: can't find home directory"
|
createDirectoryIfMissing True path
|
||||||
reqFail)
|
return $ path </> "database.json"
|
||||||
(\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
|
|
||||||
|
|
||||||
--jl
|
--jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user