more OsPath conversion

Git.Types now uses it, as does TopFilePath, making for plenty of new
compile errors needing fixing.

Sponsored-by: Brock Spratlen
This commit is contained in:
Joey Hess 2025-01-23 16:15:00 -04:00
parent 12660314f1
commit ea775baccd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
22 changed files with 159 additions and 163 deletions

View file

@ -9,28 +9,27 @@
module Config.Files where
import Common
import Utility.FreeDesktop
import Utility.Exception
import System.FilePath
{- ~/.config/git-annex/file -}
userConfigFile :: FilePath -> IO FilePath
userConfigFile :: OsPath -> IO OsPath
userConfigFile file = do
dir <- userConfigDir
return $ dir </> "git-annex" </> file
dir <- toOsPath <$> userConfigDir
return $ dir </> literalOsPath "git-annex" </> file
autoStartFile :: IO FilePath
autoStartFile = userConfigFile "autostart"
autoStartFile :: IO OsPath
autoStartFile = userConfigFile (literalOsPath "autostart")
{- The path to git-annex is written here; which is useful when something
- has installed it to some awful non-PATH location. -}
programFile :: IO FilePath
programFile = userConfigFile "program"
programFile :: IO OsPath
programFile = userConfigFile (literalOsPath "program")
{- A .noannex file in a git repository prevents git-annex from
- initializing that repository. The content of the file is returned. -}
noAnnexFileContent :: Maybe FilePath -> IO (Maybe String)
noAnnexFileContent :: Maybe OsPath -> IO (Maybe String)
noAnnexFileContent repoworktree = case repoworktree of
Nothing -> return Nothing
Just wt -> catchMaybeIO (readFile (wt </> ".noannex"))
Just wt -> catchMaybeIO (readFile (fromOsPath (wt </> literalOsPath ".noannex")))

View file

@ -14,38 +14,37 @@ import Config.Files
import Utility.Tmp
{- Returns anything listed in the autostart file (which may not exist). -}
readAutoStartFile :: IO [FilePath]
readAutoStartFile :: IO [OsPath]
readAutoStartFile = do
f <- autoStartFile
filter valid . nub . map dropTrailingPathSeparator . lines
<$> catchDefaultIO "" (readFile f)
filter valid . nub . map (dropTrailingPathSeparator . toOsPath) . lines
<$> catchDefaultIO "" (readFile (fromOsPath f))
where
-- Ignore any relative paths; some old buggy versions added eg "."
valid = isAbsolute
modifyAutoStartFile :: ([FilePath] -> [FilePath]) -> IO ()
modifyAutoStartFile :: ([OsPath] -> [OsPath]) -> IO ()
modifyAutoStartFile func = do
dirs <- readAutoStartFile
let dirs' = nubBy equalFilePath $ func dirs
when (dirs' /= dirs) $ do
f <- autoStartFile
createDirectoryIfMissing True $
fromRawFilePath (parentDir (toRawFilePath f))
createDirectoryIfMissing True (parentDir f)
viaTmp (writeFile . fromRawFilePath . fromOsPath)
(toOsPath (toRawFilePath f))
(unlines dirs')
(toOsPath f)
(unlines (map fromOsPath dirs'))
{- 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. -}
addAutoStartFile :: FilePath -> IO ()
addAutoStartFile :: OsPath -> IO ()
addAutoStartFile path = do
path' <- fromRawFilePath <$> absPath (toRawFilePath path)
path' <- absPath path
modifyAutoStartFile $ (:) path'
{- Removes a directory from the autostart file. -}
removeAutoStartFile :: FilePath -> IO ()
removeAutoStartFile :: OsPath -> IO ()
removeAutoStartFile path = do
path' <- fromRawFilePath <$> absPath (toRawFilePath path)
path' <- absPath path
modifyAutoStartFile $
filter (not . equalFilePath path')