fixes for windows

This commit is contained in:
Joey Hess 2013-05-12 13:58:46 -05:00
parent 4fe293bddf
commit 167bee746c

20
Utility/Path.hs Normal file → Executable file
View file

@ -1,6 +1,6 @@
{- path manipulation {- path manipulation
- -
- Copyright 2010-2011 Joey Hess <joey@kitenet.net> - Copyright 2010-2013 Joey Hess <joey@kitenet.net>
- -
- Licensed under the GNU GPL version 3 or higher. - Licensed under the GNU GPL version 3 or higher.
-} -}
@ -20,14 +20,18 @@ import Control.Applicative
import Utility.Monad import Utility.Monad
import Utility.UserInfo import Utility.UserInfo
{- Returns the parent directory of a path. Parent of / is "" -} {- 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 "" -}
parentDir :: FilePath -> FilePath parentDir :: FilePath -> FilePath
parentDir dir parentDir dir
| not $ null dirs = slash ++ join s (init dirs) | null dirs = ""
| otherwise = "" | otherwise = joinDrive drive (join s $ init dirs)
where where
dirs = filter (not . null) $ split s dir -- on Unix, the drive will be "/" when the dir is absolute, otherwise ""
slash = if isAbsolute dir then s else "" (drive, path) = splitDrive dir
dirs = filter (not . null) $ split s path
s = [pathSeparator] s = [pathSeparator]
prop_parentDir_basics :: FilePath -> Bool prop_parentDir_basics :: FilePath -> Bool
@ -43,7 +47,7 @@ prop_parentDir_basics dir
- are all equivilant. - are all equivilant.
-} -}
dirContains :: FilePath -> FilePath -> Bool dirContains :: FilePath -> FilePath -> Bool
dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b' dirContains a b = a == b || a' == b' || (a'++[pathSeparator]) `isPrefixOf` b'
where where
norm p = fromMaybe "" $ absNormPath p "." norm p = fromMaybe "" $ absNormPath p "."
a' = norm a a' = norm a
@ -108,7 +112,7 @@ prop_relPathDirToFile_regressionTest = same_dir_shortcurcuits_at_difference
{- Given an original list of paths, and an expanded list derived from it, {- Given an original list of paths, and an expanded list derived from it,
- generates a list of lists, where each sublist corresponds to one of the - generates a list of lists, where each sublist corresponds to one of the
- original paths. When the original path is a direcotry, any items - original paths. When the original path is a directory, any items
- in the expanded list that are contained in that directory will appear in - in the expanded list that are contained in that directory will appear in
- its segment. - its segment.
-} -}