2013-04-23 11:38:52 -04:00
|
|
|
{- git-annex extra config files
|
2012-08-02 00:42:33 -04:00
|
|
|
-
|
2019-02-05 14:43:23 -04:00
|
|
|
- Copyright 2012-2019 Joey Hess <id@joeyh.name>
|
2012-08-02 00:42:33 -04:00
|
|
|
-
|
2019-03-13 15:48:14 -04:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2012-08-02 00:42:33 -04:00
|
|
|
-}
|
|
|
|
|
2015-05-10 16:38:49 -04:00
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
2013-04-23 11:38:52 -04:00
|
|
|
module Config.Files where
|
2012-08-02 00:42:33 -04:00
|
|
|
|
2012-08-27 13:43:03 -04:00
|
|
|
import Common
|
2013-05-12 19:19:28 -04:00
|
|
|
import Utility.Tmp
|
2012-08-02 00:42:33 -04:00
|
|
|
import Utility.FreeDesktop
|
|
|
|
|
|
|
|
{- ~/.config/git-annex/file -}
|
|
|
|
userConfigFile :: FilePath -> IO FilePath
|
|
|
|
userConfigFile file = do
|
|
|
|
dir <- userConfigDir
|
|
|
|
return $ dir </> "git-annex" </> file
|
|
|
|
|
|
|
|
autoStartFile :: IO FilePath
|
|
|
|
autoStartFile = userConfigFile "autostart"
|
|
|
|
|
2013-03-03 17:07:27 -04:00
|
|
|
{- Returns anything listed in the autostart file (which may not exist). -}
|
|
|
|
readAutoStartFile :: IO [FilePath]
|
|
|
|
readAutoStartFile = do
|
|
|
|
f <- autoStartFile
|
2015-12-02 15:57:30 -04:00
|
|
|
filter valid . nub . map dropTrailingPathSeparator . lines
|
2013-04-23 12:36:37 -04:00
|
|
|
<$> catchDefaultIO "" (readFile f)
|
2015-12-02 15:57:30 -04:00
|
|
|
where
|
|
|
|
-- Ignore any relative paths; some old buggy versions added eg "."
|
|
|
|
valid = isAbsolute
|
2013-03-03 17:07:27 -04:00
|
|
|
|
2013-04-23 12:36:37 -04:00
|
|
|
modifyAutoStartFile :: ([FilePath] -> [FilePath]) -> IO ()
|
|
|
|
modifyAutoStartFile func = do
|
2013-03-03 17:07:27 -04:00
|
|
|
dirs <- readAutoStartFile
|
2013-04-23 12:36:37 -04:00
|
|
|
let dirs' = nubBy equalFilePath $ func dirs
|
|
|
|
when (dirs' /= dirs) $ do
|
2013-03-03 17:07:27 -04:00
|
|
|
f <- autoStartFile
|
2015-01-09 13:11:56 -04:00
|
|
|
createDirectoryIfMissing True (parentDir f)
|
2013-09-25 03:09:06 -04:00
|
|
|
viaTmp writeFile f $ unlines dirs'
|
2013-04-23 12:36:37 -04:00
|
|
|
|
2013-06-11 00:06:06 -04:00
|
|
|
{- Adds a directory to the autostart file. If the directory is already
|
|
|
|
- present, it's moved to the top, so it will be used as the default
|
|
|
|
- when opening the webapp. -}
|
2013-04-23 12:36:37 -04:00
|
|
|
addAutoStartFile :: FilePath -> IO ()
|
2015-12-02 15:57:30 -04:00
|
|
|
addAutoStartFile path = do
|
|
|
|
path' <- absPath path
|
|
|
|
modifyAutoStartFile $ (:) path'
|
2013-03-03 17:07:27 -04:00
|
|
|
|
|
|
|
{- Removes a directory from the autostart file. -}
|
|
|
|
removeAutoStartFile :: FilePath -> IO ()
|
2015-12-02 15:57:30 -04:00
|
|
|
removeAutoStartFile path = do
|
|
|
|
path' <- absPath path
|
|
|
|
modifyAutoStartFile $
|
|
|
|
filter (not . equalFilePath path')
|
2013-03-03 17:07:27 -04:00
|
|
|
|
2019-03-18 12:33:56 -04:00
|
|
|
{- The path to git-annex is written here; which is useful when something
|
2013-05-20 17:42:40 -04:00
|
|
|
- has installed it to some awful non-PATH location. -}
|
2012-08-02 00:42:33 -04:00
|
|
|
programFile :: IO FilePath
|
|
|
|
programFile = userConfigFile "program"
|
2012-08-27 13:43:03 -04:00
|
|
|
|
2019-02-05 14:43:23 -04:00
|
|
|
{- A .noannex file in a git repository prevents git-annex from
|
|
|
|
- initializing that repository.. The content of the file is returned. -}
|
2019-02-08 13:16:10 -04:00
|
|
|
noAnnexFileContent :: Maybe FilePath -> IO (Maybe String)
|
|
|
|
noAnnexFileContent repoworktree = case repoworktree of
|
2019-02-05 14:43:23 -04:00
|
|
|
Nothing -> return Nothing
|
|
|
|
Just wt -> catchMaybeIO (readFile (wt </> ".noannex"))
|