aboutsummaryrefslogtreecommitdiff
path: root/Utility/Path.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-01-21 13:54:47 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-01-21 13:54:47 -0400
commit7141943075211f9dd4959ca4c8b0a274f48dc9ff (patch)
treeebe584d015ca256071bcccb8de0f46aebe8ba67d /Utility/Path.hs
parent961b5d4d997999485e7b696416574cd0f8663f88 (diff)
Revert "remove absNormPathUnix, using my absPathFrom replacement"
This reverts commit b6b368ed036f2e34ee4b7d39e5b41b1ba2d0a76c. Consider: relPathDirToFile (absPathFrom "/tmp/repo/xxx" "y/bar") "/tmp/repo/.git/annex/objects/xxx" This needs to always yield "../../../.git/annex/objects/xxx" but on Windows, it is "..\\..\\/tmp/repo/.git/annex/objects/xxx"
Diffstat (limited to 'Utility/Path.hs')
-rw-r--r--Utility/Path.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/Utility/Path.hs b/Utility/Path.hs
index 5e035b221..4ff88f72e 100644
--- a/Utility/Path.hs
+++ b/Utility/Path.hs
@@ -5,7 +5,7 @@
- License: BSD-2-clause
-}
-{-# LANGUAGE CPP #-}
+{-# LANGUAGE PackageImports, CPP #-}
module Utility.Path where
@@ -24,6 +24,7 @@ import System.Posix.Files
import Utility.Exception
#endif
+import qualified "MissingH" System.Path as MissingH
import Utility.Monad
import Utility.UserInfo
@@ -64,6 +65,18 @@ simplifyPath path = dropTrailingPathSeparator $
absPathFrom :: FilePath -> FilePath -> FilePath
absPathFrom dir path = simplifyPath (combine dir path)
+{- On Windows, this converts the paths to unix-style, in order to run
+ - MissingH's absNormPath on them. Resulting path will use / separators. -}
+absNormPathUnix :: FilePath -> FilePath -> Maybe FilePath
+#ifndef mingw32_HOST_OS
+absNormPathUnix dir path = MissingH.absNormPath dir path
+#else
+absNormPathUnix dir path = todos <$> MissingH.absNormPath (fromdos dir) (fromdos path)
+ where
+ fromdos = replace "\\" "/"
+ todos = replace "/" "\\"
+#endif
+
{- takeDirectory "foo/bar/" is "foo/bar". This instead yields "foo" -}
parentDir :: FilePath -> FilePath
parentDir = takeDirectory . dropTrailingPathSeparator