diff --git a/Annex/Fixup.hs b/Annex/Fixup.hs index e0a5a33e20..35e0c5497c 100644 --- a/Annex/Fixup.hs +++ b/Annex/Fixup.hs @@ -18,6 +18,7 @@ import Utility.Directory import Utility.Exception import Utility.Monad import Utility.FileSystemEncoding +import qualified Utility.RawFilePath as R import Utility.PartialPrelude import System.IO @@ -112,9 +113,9 @@ fixupUnusualRepos r@(Repo { location = l@(Local { worktree = Just w, gitdir = d dotgit' = fromRawFilePath dotgit replacedotgit = whenM (doesFileExist dotgit') $ do - linktarget <- relPathDirToFile (fromRawFilePath w) (fromRawFilePath d) + linktarget <- relPathDirToFile w d nukeFile dotgit' - createSymbolicLink linktarget dotgit' + R.createSymbolicLink linktarget dotgit' unsetcoreworktree = maybe (error "unset core.worktree failed") (\_ -> return ()) diff --git a/Git/CheckAttr.hs b/Git/CheckAttr.hs index 04e5d1e4f7..ae50acee64 100644 --- a/Git/CheckAttr.hs +++ b/Git/CheckAttr.hs @@ -12,6 +12,7 @@ import Git import Git.Command import Utility.Path.AbsRel import qualified Utility.CoProcess as CoProcess +import qualified Utility.RawFilePath as R import System.IO.Error import qualified Data.ByteString as B @@ -24,7 +25,7 @@ type Attr = String - values and returns a handle. -} checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle checkAttrStart attrs repo = do - currdir <- toRawFilePath <$> getCurrentDirectory + currdir <- R.getCurrentDirectory h <- gitCoProcessStart True params repo return (h, attrs, currdir) where diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index e99b25a2b9..d99900bddb 100644 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -66,10 +66,10 @@ get = do configure Nothing (Just r) = Git.Config.read r configure (Just d) _ = do - absd <- absPath d + absd <- absPath (fromRawFilePath d) curr <- getCurrentDirectory loc <- adjustGitDirFile $ Local - { gitdir = toRawFilePath absd + { gitdir = absd , worktree = Just (toRawFilePath curr) } r <- Git.Config.read $ newFrom loc diff --git a/Git/LsFiles.hs b/Git/LsFiles.hs index c839291678..3ba4ae9967 100644 --- a/Git/LsFiles.hs +++ b/Git/LsFiles.hs @@ -38,6 +38,7 @@ import Utility.InodeCache import Utility.TimeStamp import Utility.Attoparsec import Utility.Path.AbsRel +import qualified Utility.RawFilePath as R import System.Posix.Types import qualified Data.Map as M @@ -214,7 +215,7 @@ typeChanged' ps l repo = guardSafeForLsFiles repo $ do -- git diff returns filenames relative to the top of the git repo; -- convert to filenames relative to the cwd, like git ls-files. top <- absPath (repoPath repo) - currdir <- toRawFilePath <$> getCurrentDirectory + currdir <- R.getCurrentDirectory return (map (\f -> relPathDirToFileAbs currdir $ top P. f) fs, cleanup) where prefix = diff --git a/Utility/RawFilePath.hs b/Utility/RawFilePath.hs index b4c1d028bc..ebbbabc4bd 100644 --- a/Utility/RawFilePath.hs +++ b/Utility/RawFilePath.hs @@ -1,4 +1,5 @@ -{- Portability shim around System.Posix.Files.ByteString +{- Portability shim around System.Posix.Files.ByteString and + - System.Posix.Directory.ByteString - - On unix, this makes syscalls using RawFilesPaths as efficiently as - possible. @@ -7,7 +8,7 @@ - decoded. So this library will work, but less efficiently than using - FilePath would. - - - Copyright 2019 Joey Hess + - Copyright 2019-2020 Joey Hess - - License: BSD-2-clause -} @@ -17,20 +18,26 @@ module Utility.RawFilePath ( RawFilePath, readSymbolicLink, + createSymbolicLink, getFileStatus, getSymbolicLinkStatus, doesPathExist, + getCurrentDirectory, ) where #ifndef mingw32_HOST_OS import Utility.FileSystemEncoding (RawFilePath) import System.Posix.Files.ByteString +import System.Posix.Directory.ByteString -- | Checks if a file or directoy exists. Note that a dangling symlink -- will be false. doesPathExist :: RawFilePath -> IO Bool doesPathExist = fileExist +getCurrentDirectory :: IO RawFilePath +getCurrentDirectory = getWorkingDirectory + #else import qualified Data.ByteString as B import System.PosixCompat (FileStatus) @@ -41,6 +48,11 @@ import Utility.FileSystemEncoding readSymbolicLink :: RawFilePath -> IO RawFilePath readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f) +createSymbolicLink :: RawFilePath -> RawFilePath -> IO () +createSymbolicLink a b = P.createSymbolicLink + (fromRawFilePath a) + (fromRawFilePath b) + getFileStatus :: RawFilePath -> IO FileStatus getFileStatus = P.getFileStatus . fromRawFilePath @@ -49,4 +61,7 @@ getSymbolicLinkStatus = P.getSymbolicLinkStatus . fromRawFilePath doesPathExist :: RawFilePath -> IO Bool doesPathExist = D.doesPathExist . fromRawFilePath + +getCurrentDirectory :: IO RawFilePath +getCurrentDirectory = toRawFilePath <$> D.getCurrentDirectory #endif