RawFilePath version of getCurrentDirectory

This commit was sponsored by Jochen Bartl on Patreon
This commit is contained in:
Joey Hess 2020-10-28 16:03:45 -04:00
parent 08cbaee1f8
commit 6c29817748
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 26 additions and 8 deletions

View file

@ -18,6 +18,7 @@ import Utility.Directory
import Utility.Exception import Utility.Exception
import Utility.Monad import Utility.Monad
import Utility.FileSystemEncoding import Utility.FileSystemEncoding
import qualified Utility.RawFilePath as R
import Utility.PartialPrelude import Utility.PartialPrelude
import System.IO import System.IO
@ -112,9 +113,9 @@ fixupUnusualRepos r@(Repo { location = l@(Local { worktree = Just w, gitdir = d
dotgit' = fromRawFilePath dotgit dotgit' = fromRawFilePath dotgit
replacedotgit = whenM (doesFileExist dotgit') $ do replacedotgit = whenM (doesFileExist dotgit') $ do
linktarget <- relPathDirToFile (fromRawFilePath w) (fromRawFilePath d) linktarget <- relPathDirToFile w d
nukeFile dotgit' nukeFile dotgit'
createSymbolicLink linktarget dotgit' R.createSymbolicLink linktarget dotgit'
unsetcoreworktree = unsetcoreworktree =
maybe (error "unset core.worktree failed") (\_ -> return ()) maybe (error "unset core.worktree failed") (\_ -> return ())

View file

@ -12,6 +12,7 @@ import Git
import Git.Command import Git.Command
import Utility.Path.AbsRel import Utility.Path.AbsRel
import qualified Utility.CoProcess as CoProcess import qualified Utility.CoProcess as CoProcess
import qualified Utility.RawFilePath as R
import System.IO.Error import System.IO.Error
import qualified Data.ByteString as B import qualified Data.ByteString as B
@ -24,7 +25,7 @@ type Attr = String
- values and returns a handle. -} - values and returns a handle. -}
checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle checkAttrStart :: [Attr] -> Repo -> IO CheckAttrHandle
checkAttrStart attrs repo = do checkAttrStart attrs repo = do
currdir <- toRawFilePath <$> getCurrentDirectory currdir <- R.getCurrentDirectory
h <- gitCoProcessStart True params repo h <- gitCoProcessStart True params repo
return (h, attrs, currdir) return (h, attrs, currdir)
where where

View file

@ -66,10 +66,10 @@ get = do
configure Nothing (Just r) = Git.Config.read r configure Nothing (Just r) = Git.Config.read r
configure (Just d) _ = do configure (Just d) _ = do
absd <- absPath d absd <- absPath (fromRawFilePath d)
curr <- getCurrentDirectory curr <- getCurrentDirectory
loc <- adjustGitDirFile $ Local loc <- adjustGitDirFile $ Local
{ gitdir = toRawFilePath absd { gitdir = absd
, worktree = Just (toRawFilePath curr) , worktree = Just (toRawFilePath curr)
} }
r <- Git.Config.read $ newFrom loc r <- Git.Config.read $ newFrom loc

View file

@ -38,6 +38,7 @@ import Utility.InodeCache
import Utility.TimeStamp import Utility.TimeStamp
import Utility.Attoparsec import Utility.Attoparsec
import Utility.Path.AbsRel import Utility.Path.AbsRel
import qualified Utility.RawFilePath as R
import System.Posix.Types import System.Posix.Types
import qualified Data.Map as M 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; -- git diff returns filenames relative to the top of the git repo;
-- convert to filenames relative to the cwd, like git ls-files. -- convert to filenames relative to the cwd, like git ls-files.
top <- absPath (repoPath repo) top <- absPath (repoPath repo)
currdir <- toRawFilePath <$> getCurrentDirectory currdir <- R.getCurrentDirectory
return (map (\f -> relPathDirToFileAbs currdir $ top P.</> f) fs, cleanup) return (map (\f -> relPathDirToFileAbs currdir $ top P.</> f) fs, cleanup)
where where
prefix = prefix =

View 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 - On unix, this makes syscalls using RawFilesPaths as efficiently as
- possible. - possible.
@ -7,7 +8,7 @@
- decoded. So this library will work, but less efficiently than using - decoded. So this library will work, but less efficiently than using
- FilePath would. - FilePath would.
- -
- Copyright 2019 Joey Hess <id@joeyh.name> - Copyright 2019-2020 Joey Hess <id@joeyh.name>
- -
- License: BSD-2-clause - License: BSD-2-clause
-} -}
@ -17,20 +18,26 @@
module Utility.RawFilePath ( module Utility.RawFilePath (
RawFilePath, RawFilePath,
readSymbolicLink, readSymbolicLink,
createSymbolicLink,
getFileStatus, getFileStatus,
getSymbolicLinkStatus, getSymbolicLinkStatus,
doesPathExist, doesPathExist,
getCurrentDirectory,
) where ) where
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
import Utility.FileSystemEncoding (RawFilePath) import Utility.FileSystemEncoding (RawFilePath)
import System.Posix.Files.ByteString import System.Posix.Files.ByteString
import System.Posix.Directory.ByteString
-- | Checks if a file or directoy exists. Note that a dangling symlink -- | Checks if a file or directoy exists. Note that a dangling symlink
-- will be false. -- will be false.
doesPathExist :: RawFilePath -> IO Bool doesPathExist :: RawFilePath -> IO Bool
doesPathExist = fileExist doesPathExist = fileExist
getCurrentDirectory :: IO RawFilePath
getCurrentDirectory = getWorkingDirectory
#else #else
import qualified Data.ByteString as B import qualified Data.ByteString as B
import System.PosixCompat (FileStatus) import System.PosixCompat (FileStatus)
@ -41,6 +48,11 @@ import Utility.FileSystemEncoding
readSymbolicLink :: RawFilePath -> IO RawFilePath readSymbolicLink :: RawFilePath -> IO RawFilePath
readSymbolicLink f = toRawFilePath <$> P.readSymbolicLink (fromRawFilePath f) 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 :: RawFilePath -> IO FileStatus
getFileStatus = P.getFileStatus . fromRawFilePath getFileStatus = P.getFileStatus . fromRawFilePath
@ -49,4 +61,7 @@ getSymbolicLinkStatus = P.getSymbolicLinkStatus . fromRawFilePath
doesPathExist :: RawFilePath -> IO Bool doesPathExist :: RawFilePath -> IO Bool
doesPathExist = D.doesPathExist . fromRawFilePath doesPathExist = D.doesPathExist . fromRawFilePath
getCurrentDirectory :: IO RawFilePath
getCurrentDirectory = toRawFilePath <$> D.getCurrentDirectory
#endif #endif