import Utility.Exception
import Utility.Monad
import Utility.FileSystemEncoding
+import qualified Utility.RawFilePath as R
import Utility.PartialPrelude
import System.IO
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 ())
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
- 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
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
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
-- 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 =
-{- 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.
- decoded. So this library will work, but less efficiently than using
- FilePath would.
-
- - Copyright 2019 Joey Hess <id@joeyh.name>
+ - Copyright 2019-2020 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
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)
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
doesPathExist :: RawFilePath -> IO Bool
doesPathExist = D.doesPathExist . fromRawFilePath
+
+getCurrentDirectory :: IO RawFilePath
+getCurrentDirectory = toRawFilePath <$> D.getCurrentDirectory
#endif