diff options
-rw-r--r-- | sensible-directory/src/SensibleDir.hs | 47 |
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 #-} |
3 | module SensibleDir where | 3 | module SensibleDir where |
4 | 4 | ||
5 | import Paths_testcabaldir | ||
6 | import System.Directory | 5 | import System.Directory |
7 | #ifdef VERSION_directory_xdg | 6 | #ifdef VERSION_directory_xdg |
8 | import System.DirectoryXdg | 7 | import System.DirectoryXdg |
@@ -15,36 +14,15 @@ import Control.Arrow | |||
15 | import Control.Applicative | 14 | import Control.Applicative |
16 | import Data.List | 15 | import Data.List |
17 | 16 | ||
18 | installScenario = NotInstalled | ||
19 | doit = 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 | |||
39 | runningInBuildDir :: IO Bool | 17 | runningInBuildDir :: IO Bool |
40 | runningInBuildDir = any (=="build") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath | 18 | runningInBuildDir = any (=="build") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath |
41 | 19 | ||
42 | runningInCabalDir :: IO Bool | 20 | runningInCabalDir :: IO Bool |
43 | runningInCabalDir = any (==".cabal") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath | 21 | runningInCabalDir = any (==".cabal") . take 2 . reverse . splitDirectories . takeDirectory <$> getExecutablePath |
44 | 22 | ||
45 | runningInSysBin = do | 23 | runningInSysBin = 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 | ||
55 | runningInLocalBin = do | 33 | runningInLocalBin = 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 | |||
91 | isUnix os = not $ "mingw" `isPrefixOf` os | 67 | isUnix 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) |
96 | sensibleCacheDir suffix = do | 72 | sensibleCacheDir 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) |