RawFilePath version of getCurrentDirectory
authorJoey Hess <joeyh@joeyh.name>
Wed, 28 Oct 2020 20:03:45 +0000 (16:03 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 28 Oct 2020 20:03:45 +0000 (16:03 -0400)
This commit was sponsored by Jochen Bartl on Patreon

Annex/Fixup.hs
Git/CheckAttr.hs
Git/CurrentRepo.hs
Git/LsFiles.hs
Utility/RawFilePath.hs

index e0a5a33e201ffeae33b5e77bbb61da5037882f7a..35e0c5497c96d32be2bc303de5cb9ab05b57520c 100644 (file)
@@ -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 ())
index 04e5d1e4f70efbbe6aa153f465a800d61139d3c4..ae50acee647edaf19d28814f0d6f67ad977bd81d 100644 (file)
@@ -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
index e99b25a2b954664c94fc948d6066f7fad8b6c63d..d99900bddbf111a20fbfb491a597a6073b03f729 100644 (file)
@@ -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
index c839291678c52ff8be458d85a40c8931d53cba02..3ba4ae99673f9544398eaa9f3cb2a18af492ac5e 100644 (file)
@@ -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 = 
index b4c1d028bc47c43c30a15cb698418816954c6476..ebbbabc4bdfe3696bc1aa87be0ea00ed853c2fe5 100644 (file)
@@ -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 <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)
@@ -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