aboutsummaryrefslogtreecommitdiff
path: root/Utility/Path.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-01-09 13:11:56 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-01-09 13:11:56 -0400
commit425bc1107aebdb701cdcee44da731dd918cd470d (patch)
tree25bcacb37277b70aa7bd0caaf0fe7c3edc665653 /Utility/Path.hs
parent20c7644a4d85434cf49840ea92fca0c723710c72 (diff)
revert parentDir change
Reverts 2bba5bc22d049272d3328bfa6c452d3e2e50e86c Unfortunately, this caused breakage on Windows, and possibly elsewhere, because parentDir and takeDirectory do not behave the same when there is a trailing directory separator.
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r--Utility/Path.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs
index cc6c35485..763654db2 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -77,12 +77,18 @@ absNormPathUnix dir path = todos <$> MissingH.absNormPath (fromdos dir) (fromdos
todos = replace "/" "\\"
#endif
-{- Just the parent directory of a path, or Nothing if the path has no
- - parent (ie for "/") -}
-parentDir :: FilePath -> Maybe FilePath
+{- Returns the parent directory of a path.
+ -
+ - To allow this to be easily used in loops, which terminate upon reaching the
+ - top, the parent of / is ""
+ -
+ - An additional subtle difference between this and takeDirectory
+ - is that takeDirectory "foo/bar/" is "foo/bar", while parentDir is "foo"
+ -}
+parentDir :: FilePath -> FilePath
parentDir dir
- | null dirs = Nothing
- | otherwise = Just $ joinDrive drive (join s $ init dirs)
+ | null dirs = ""
+ | otherwise = joinDrive drive (join s $ init dirs)
where
-- on Unix, the drive will be "/" when the dir is absolute, otherwise ""
(drive, path) = splitDrive dir
@@ -92,8 +98,8 @@ parentDir dir
prop_parentDir_basics :: FilePath -> Bool
prop_parentDir_basics dir
| null dir = True
- | dir == "/" = parentDir dir == Nothing
- | otherwise = p /= Just dir
+ | dir == "/" = parentDir dir == ""
+ | otherwise = p /= dir
where
p = parentDir dir