fileRef: make paths relative and simplified
Fix behavior of several commands, including reinject, addurl, and rmurl when given an absolute path to an unlocked file, or a relative path that leaves and re-enters the repository. To avoid slowing down all the cases where the paths are already ok with an unncessary call to getCurrentDirectory, put in an optimisation in relPathCwdToFile. That will probably also speed up other parts of git-annex by some small amount, but I have not benchmarked. Note that I did not convert branchFileRef, because it seems likely that it will be used with a file that is not provided by the user, so is already in a sane format. This is certainly true for the way git-annex uses it, though maybe arguable to the extent Git.Ref is a reusable library.
This commit is contained in:
parent
6b980c1514
commit
4bf7940d6b
5 changed files with 32 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
|||
{- absolute and relative path manipulation
|
||||
-
|
||||
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2021 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
@ -19,6 +19,7 @@ module Utility.Path.AbsRel (
|
|||
) where
|
||||
|
||||
import System.FilePath.ByteString
|
||||
import qualified Data.ByteString as B
|
||||
#ifdef mingw32_HOST_OS
|
||||
import System.Directory (getCurrentDirectory)
|
||||
#else
|
||||
|
@ -72,13 +73,17 @@ absPath file
|
|||
- relPathCwdToFile "../bar/baz" == "baz"
|
||||
-}
|
||||
relPathCwdToFile :: RawFilePath -> IO RawFilePath
|
||||
relPathCwdToFile f = do
|
||||
relPathCwdToFile f
|
||||
-- Optimisation: Avoid doing any IO when the path is relative
|
||||
-- and does not contain any ".." component.
|
||||
| isRelative f && not (".." `B.isInfixOf` f) = return f
|
||||
| otherwise = do
|
||||
#ifdef mingw32_HOST_OS
|
||||
c <- toRawFilePath <$> getCurrentDirectory
|
||||
c <- toRawFilePath <$> getCurrentDirectory
|
||||
#else
|
||||
c <- getWorkingDirectory
|
||||
c <- getWorkingDirectory
|
||||
#endif
|
||||
relPathDirToFile c f
|
||||
relPathDirToFile c f
|
||||
|
||||
{- Constructs a minimal relative path from a directory to a file. -}
|
||||
relPathDirToFile :: RawFilePath -> RawFilePath -> IO RawFilePath
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue