diff options
author | Joey Hess <joey@kitenet.net> | 2011-01-31 20:14:08 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-01-31 20:15:23 -0400 |
commit | 27056daccd1a2f541cd104a835a32523a532d4da (patch) | |
tree | b4b595f287efb3496f21a5f74c034e897e5da075 /Utility.hs | |
parent | 37c62eebb72fa0c216336435669cf8a05c2dbc88 (diff) |
cleanup last change
Diffstat (limited to 'Utility.hs')
-rw-r--r-- | Utility.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Utility.hs b/Utility.hs index 96bbc89ee..2bb623532 100644 --- a/Utility.hs +++ b/Utility.hs @@ -18,6 +18,7 @@ module Utility ( unsetFileMode, readMaybe, safeWriteFile, + dirContains, prop_idempotent_shellEscape, prop_idempotent_shellEscape_multiword, @@ -36,6 +37,7 @@ import System.Path import System.FilePath import System.Directory import Foreign (complement) +import Data.List {- A version of hgetContents that is not lazy. Ensures file is - all read before it gets closed. -} @@ -65,6 +67,19 @@ prop_parentDir_basics dir where p = parentDir dir +{- Checks if the first FilePath is, or could be said to contain the second. + - For example, "foo/" contains "foo/bar". Also, "foo", "./foo", "foo/" etc + - are all equivilant. + -} +dirContains :: FilePath -> FilePath -> Bool +dirContains a b = a == b || a' == b' || (a'++"/") `isPrefixOf` b' + where + norm p = case (absNormPath p ".") of + Just r -> r + Nothing -> "" + a' = norm a + b' = norm b + {- Converts a filename into a normalized, absolute path. -} absPath :: FilePath -> IO FilePath absPath file = do |