summaryrefslogtreecommitdiff
path: root/src/Utility/Path.hs
diff options
context:
space:
mode:
authorJoey Hess2015-12-15 21:08:22 -0400
committerJoey Hess2015-12-15 21:08:22 -0400
commit47a2b72bed3770d3dfb26c4142479c436a11ce55 (patch)
tree3d67f32c91338193a21aadb26f0d001d5cec9670 /src/Utility/Path.hs
parent571318218c5598ad841cc3dff73c9fee2c7216ef (diff)
Merged Utility changes from git-annex.
Diffstat (limited to 'src/Utility/Path.hs')
-rw-r--r--src/Utility/Path.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/Utility/Path.hs b/src/Utility/Path.hs
index 8e3c2bdd..f3290d8d 100644
--- a/src/Utility/Path.hs
+++ b/src/Utility/Path.hs
@@ -30,8 +30,8 @@ import qualified "MissingH" System.Path as MissingH
import Utility.Monad
import Utility.UserInfo
-{- Simplifies a path, removing any ".." or ".", and removing the trailing
- - path separator.
+{- Simplifies a path, removing any "." component, collapsing "dir/..",
+ - and removing the trailing path separator.
-
- On Windows, preserves whichever style of path separator might be used in
- the input FilePaths. This is done because some programs in Windows
@@ -50,7 +50,8 @@ simplifyPath path = dropTrailingPathSeparator $
norm c [] = reverse c
norm c (p:ps)
- | p' == ".." = norm (drop 1 c) ps
+ | p' == ".." && not (null c) && dropTrailingPathSeparator (c !! 0) /= ".." =
+ norm (drop 1 c) ps
| p' == "." = norm c ps
| otherwise = norm (p:c) ps
where
@@ -88,7 +89,7 @@ parentDir = takeDirectory . dropTrailingPathSeparator
upFrom :: FilePath -> Maybe FilePath
upFrom dir
| length dirs < 2 = Nothing
- | otherwise = Just $ joinDrive drive (join s $ init dirs)
+ | otherwise = Just $ joinDrive drive (intercalate s $ init dirs)
where
-- on Unix, the drive will be "/" when the dir is absolute, otherwise ""
(drive, path) = splitDrive dir
@@ -148,7 +149,7 @@ relPathDirToFile from to = relPathDirToFileAbs <$> absPath from <*> absPath to
relPathDirToFileAbs :: FilePath -> FilePath -> FilePath
relPathDirToFileAbs from to
| takeDrive from /= takeDrive to = to
- | otherwise = join s $ dotdots ++ uncommon
+ | otherwise = intercalate s $ dotdots ++ uncommon
where
s = [pathSeparator]
pfrom = split s from
@@ -287,7 +288,6 @@ fileNameLengthLimit dir = do
if l <= 0
then return 255
else return $ minimum [l, 255]
- where
#endif
{- Given a string that we'd like to use as the basis for FilePath, but that