From 27056daccd1a2f541cd104a835a32523a532d4da Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 31 Jan 2011 20:14:08 -0400 Subject: cleanup last change --- Utility.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Utility.hs') 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 -- cgit v1.2.3