summaryrefslogtreecommitdiff
path: root/Config
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2013-04-23 12:36:37 -0400
committerJoey Hess <joey@kitenet.net>2013-04-23 12:36:37 -0400
commit834ce10ced7e25f7529d4bca4c006a7b186f5926 (patch)
treeafaf15eacba85fac2f6fae7b56954e13f1a6fb06 /Config
parentf3ef6fe6a713bbae9f22c59662aad51ca9b89147 (diff)
better autostart file modification
As well as just being nicer, and less code, this uses nubBy equalFilePath to ensure that the autostart file never gets dups. Also, removing from the file no longer needs to be a perfect string match; it also uses equalFilePath.
Diffstat (limited to 'Config')
-rw-r--r--Config/Files.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/Config/Files.hs b/Config/Files.hs
index e51e8a747e..45f478eeb4 100644
--- a/Config/Files.hs
+++ b/Config/Files.hs
@@ -24,26 +24,26 @@ autoStartFile = userConfigFile "autostart"
readAutoStartFile :: IO [FilePath]
readAutoStartFile = do
f <- autoStartFile
- nub . lines <$> catchDefaultIO "" (readFile f)
+ nub . map dropTrailingPathSeparator . lines
+ <$> catchDefaultIO "" (readFile f)
-{- Adds a directory to the autostart file. -}
-addAutoStartFile :: FilePath -> IO ()
-addAutoStartFile path = do
+modifyAutoStartFile :: ([FilePath] -> [FilePath]) -> IO ()
+modifyAutoStartFile func = do
dirs <- readAutoStartFile
- when (path `notElem` dirs) $ do
+ let dirs' = nubBy equalFilePath $ func dirs
+ when (dirs' /= dirs) $ do
f <- autoStartFile
createDirectoryIfMissing True (parentDir f)
- viaTmp writeFile f $ unlines $ dirs ++ [path]
+ viaTmp writeFile f $ unlines $ dirs'
+
+{- Adds a directory to the autostart file. -}
+addAutoStartFile :: FilePath -> IO ()
+addAutoStartFile path = modifyAutoStartFile $ (:) path
{- Removes a directory from the autostart file. -}
removeAutoStartFile :: FilePath -> IO ()
-removeAutoStartFile path = do
- dirs <- readAutoStartFile
- when (path `elem` dirs) $ do
- f <- autoStartFile
- createDirectoryIfMissing True (parentDir f)
- viaTmp writeFile f $ unlines $
- filter (not . equalFilePath path) dirs
+removeAutoStartFile path = modifyAutoStartFile $
+ filter (not . equalFilePath path)
{- The path to git-annex is written here; which is useful when cabal
- has installed it to some aweful non-PATH location. -}