summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sensible-directory/src/SensibleDir.hs47
1 files changed, 15 insertions, 32 deletions
diff --git a/sensible-directory/src/SensibleDir.hs b/sensible-directory/src/SensibleDir.hs
index c5f9ae1f..61515001 100644
--- a/sensible-directory/src/SensibleDir.hs
+++ b/sensible-directory/src/SensibleDir.hs
@@ -2,7 +2,6 @@
2{-# LANGUAGE TupleSections #-} 2{-# LANGUAGE TupleSections #-}
3module SensibleDir where 3module SensibleDir where
4 4
5import Paths_testcabaldir
6import System.Directory 5import System.Directory
7#ifdef VERSION_directory_xdg 6#ifdef VERSION_directory_xdg
8import System.DirectoryXdg 7import System.DirectoryXdg
@@ -15,36 +14,15 @@ import Control.Arrow
15import Control.Applicative 14import Control.Applicative
16import Data.List 15import Data.List
17 16
18installScenario = NotInstalled
19doit = do
20 ddir <- getDataDir
21 ldir <- getLibDir
22 pname <- getProgName
23 ppath <- getExecutablePath
24 sysconfdir <- getSysconfDir
25 putStrLn ("ddir = " ++ ddir);
26 putStrLn ("ldir = " ++ ldir);
27 putStrLn ("sysconfdir = " ++ sysconfdir);
28 putStrLn ("pname = " ++ pname);
29 putStr "runningInBuildDir = "
30 print =<< runningInBuildDir
31 putStr "detectLikelyInstall = "
32 print =<< detectLikelyInstall
33 putStrLn "---------------------"
34 putStr "sensibleCacheDir = "
35 print =<< sensibleCacheDir pname
36 -- putStr "sensibleConfigDir = "
37 -- print =<< sensibleConfigDir pname
38
39runningInBuildDir :: IO Bool 17runningInBuildDir :: IO Bool
40runningInBuildDir = any (=="build") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath 18runningInBuildDir = any (=="build") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath
41 19
42runningInCabalDir :: IO Bool 20runningInCabalDir :: IO Bool
43runningInCabalDir = any (==".cabal") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath 21runningInCabalDir = any (==".cabal") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath
44 22
45runningInSysBin = do 23runningInSysBin = do
46 exedir <- splitDirectories . takeDirectory <$> getExecutablePath 24 exedir <- splitDirectories . takeDirectory <$> getExecutablePath
47 return $ 25 return $
48 case take 3 (drop 1 exedir) of 26 case take 3 (drop 1 exedir) of
49 ["bin"] -> True 27 ["bin"] -> True
50 ["sbin"] -> True 28 ["sbin"] -> True
@@ -54,9 +32,7 @@ runningInSysBin = do
54 32
55runningInLocalBin = do 33runningInLocalBin = do
56 exedir <- splitDirectories . takeDirectory <$> getExecutablePath 34 exedir <- splitDirectories . takeDirectory <$> getExecutablePath
57 putStr "exedir = " 35 return $
58 print exedir
59 return $
60 case take 3 (drop 1 exedir) of 36 case take 3 (drop 1 exedir) of
61 ["usr","local","bin"] -> True 37 ["usr","local","bin"] -> True
62 ["usr","local","sbin"] -> True 38 ["usr","local","sbin"] -> True
@@ -91,7 +67,7 @@ detectLikelyInstall = do
91isUnix os = not $ "mingw" `isPrefixOf` os 67isUnix os = not $ "mingw" `isPrefixOf` os
92 68
93-- | Try to get the cache directory appropriate to the install scenario. 69-- | Try to get the cache directory appropriate to the install scenario.
94-- On windows it just calls getAppUserDataDirectory and appends "cache". 70-- On windows it just calls getAppUserDataDirectory and appends "cache".
95-- (windows behavior subject to change, contributions welcome) 71-- (windows behavior subject to change, contributions welcome)
96sensibleCacheDir suffix = do 72sensibleCacheDir suffix = do
97 let ifunix x = if isUnix os then x 73 let ifunix x = if isUnix os then x
@@ -101,11 +77,18 @@ sensibleCacheDir suffix = do
101 PrefixInstall -> do 77 PrefixInstall -> do
102 if isUnix os 78 if isUnix os
103 then do 79 then do
104 dir <- splitDirectories . takeDirectory <$> getExecutablePath 80 dirs <- splitDirectories . takeDirectory <$> getExecutablePath
105 let rdir = reverse dir 81 homedir <- getHomeDirectory
82 let rdir = reverse dirs
106 case take 1 rdir of 83 case take 1 rdir of
107 ["bin"] -> return $ (foldl1 combine $ reverse (drop 1 rdir)) </> "cache" </> suffix 84 ["bin"] -> do
108 _ -> fmap ((</> suffix) . (</> "cache") . takeDirectory) getExecutablePath 85 let dir = foldl1 combine $ reverse (drop 1 rdir)
86 if homedir == dir then getXdgDirectory XdgCache suffix
87 else return (dir </> "cache" </> suffix)
88 _ -> do
89 let dir = foldl1 combine dirs
90 if homedir == dir then getXdgDirectory XdgCache suffix
91 else return (dir </> "cache" </> suffix)
109 else getAppUserDataDirectory ("cache" </> suffix) 92 else getAppUserDataDirectory ("cache" </> suffix)
110 SystemInstall -> return ("/var/cache" </> suffix) 93 SystemInstall -> return ("/var/cache" </> suffix)
111 LocalInstall -> return ("/var/local/cache" </> suffix) 94 LocalInstall -> return ("/var/local/cache" </> suffix)