summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-15 19:01:20 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-15 19:01:20 -0400
commit23f95ac6df5f25613ac2904c23821f3ca3054246 (patch)
tree24909b0c8a1eeaf34d0744a0a3c0f591f105dc60
parent0989dd2694e4be1bc851d0a50903ceaaa988907a (diff)
use some library functions
retry with a bugfix
-rw-r--r--Utility.hs22
1 files changed, 12 insertions, 10 deletions
diff --git a/Utility.hs b/Utility.hs
index a8324815e..e04b44e6f 100644
--- a/Utility.hs
+++ b/Utility.hs
@@ -13,6 +13,7 @@ import System.IO
import System.Posix.IO
import Data.String.Utils
import System.Path
+import System.FilePath
import System.Directory
{- Let's just say that Haskell makes reading/writing a file with
@@ -38,11 +39,13 @@ hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
parentDir :: String -> String
parentDir dir =
if length dirs > 0
- then absolute ++ (join "/" $ take ((length dirs) - 1) dirs)
+ then slash ++ (join s $ take ((length dirs) - 1) dirs)
else ""
where
- dirs = filter (\x -> length x > 0) $ split "/" dir
- absolute = if ((dir !! 0) == '/') then "/" else ""
+ dirs = filter (\x -> length x > 0) $
+ split s dir
+ slash = if (not $ isAbsolute dir) then "" else s
+ s = [pathSeparator]
{- Constructs a relative path from the CWD to a directory.
-
@@ -68,20 +71,19 @@ relPathCwdToDir dir = do
- Both directories must be absolute, and normalized (eg with absNormpath).
-
- The path will end with "/", unless it is empty.
- - -}
+ -}
relPathDirToDir :: FilePath -> FilePath -> FilePath
relPathDirToDir from to =
if (0 < length path)
- then if (endswith "/" path)
- then path
- else path ++ "/"
+ then addTrailingPathSeparator path
else ""
where
- pfrom = split "/" from
- pto = split "/" to
+ s = [pathSeparator]
+ pfrom = split s from
+ pto = split s to
common = map fst $ filter same $ zip pfrom pto
same (c,d) = c == d
uncommon = drop numcommon pto
dotdots = take ((length pfrom) - numcommon) $ repeat ".."
numcommon = length $ common
- path = join "/" $ dotdots ++ uncommon
+ path = join s $ dotdots ++ uncommon