From ef663b39b09cfdaaad12eb580ed52830ebf0cd2c Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 20 Mar 2020 17:24:14 -0400 Subject: [PATCH] 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 --- app/Main.hs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index dc3b322..a75a659 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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