Revert "use some library functions"
This reverts commit 8e742bd89e
.
meh?
This commit is contained in:
parent
44b8f7c95d
commit
0989dd2694
1 changed files with 10 additions and 12 deletions
22
Utility.hs
22
Utility.hs
|
@ -13,7 +13,6 @@ import System.IO
|
||||||
import System.Posix.IO
|
import System.Posix.IO
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import System.Path
|
import System.Path
|
||||||
import System.FilePath
|
|
||||||
import System.Directory
|
import System.Directory
|
||||||
|
|
||||||
{- Let's just say that Haskell makes reading/writing a file with
|
{- Let's just say that Haskell makes reading/writing a file with
|
||||||
|
@ -39,13 +38,11 @@ hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
|
||||||
parentDir :: String -> String
|
parentDir :: String -> String
|
||||||
parentDir dir =
|
parentDir dir =
|
||||||
if length dirs > 0
|
if length dirs > 0
|
||||||
then slash ++ (join s $ take ((length dirs) - 1) dirs)
|
then absolute ++ (join "/" $ take ((length dirs) - 1) dirs)
|
||||||
else ""
|
else ""
|
||||||
where
|
where
|
||||||
dirs = filter (\x -> length x > 0) $
|
dirs = filter (\x -> length x > 0) $ split "/" dir
|
||||||
split s dir
|
absolute = if ((dir !! 0) == '/') then "/" else ""
|
||||||
slash = if (isAbsolute dir) then "" else s
|
|
||||||
s = [pathSeparator]
|
|
||||||
|
|
||||||
{- Constructs a relative path from the CWD to a directory.
|
{- Constructs a relative path from the CWD to a directory.
|
||||||
-
|
-
|
||||||
|
@ -71,19 +68,20 @@ relPathCwdToDir dir = do
|
||||||
- Both directories must be absolute, and normalized (eg with absNormpath).
|
- Both directories must be absolute, and normalized (eg with absNormpath).
|
||||||
-
|
-
|
||||||
- The path will end with "/", unless it is empty.
|
- The path will end with "/", unless it is empty.
|
||||||
-}
|
- -}
|
||||||
relPathDirToDir :: FilePath -> FilePath -> FilePath
|
relPathDirToDir :: FilePath -> FilePath -> FilePath
|
||||||
relPathDirToDir from to =
|
relPathDirToDir from to =
|
||||||
if (0 < length path)
|
if (0 < length path)
|
||||||
then addTrailingPathSeparator path
|
then if (endswith "/" path)
|
||||||
|
then path
|
||||||
|
else path ++ "/"
|
||||||
else ""
|
else ""
|
||||||
where
|
where
|
||||||
s = [pathSeparator]
|
pfrom = split "/" from
|
||||||
pfrom = split s from
|
pto = split "/" to
|
||||||
pto = split s to
|
|
||||||
common = map fst $ filter same $ zip pfrom pto
|
common = map fst $ filter same $ zip pfrom pto
|
||||||
same (c,d) = c == d
|
same (c,d) = c == d
|
||||||
uncommon = drop numcommon pto
|
uncommon = drop numcommon pto
|
||||||
dotdots = take ((length pfrom) - numcommon) $ repeat ".."
|
dotdots = take ((length pfrom) - numcommon) $ repeat ".."
|
||||||
numcommon = length $ common
|
numcommon = length $ common
|
||||||
path = join s $ dotdots ++ uncommon
|
path = join "/" $ dotdots ++ uncommon
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue