Add getAllParents

This commit is contained in:
Julian Ospald 2016-04-03 16:20:38 +02:00
parent 3c3a2d2766
commit 3a52a9ea4b
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

View File

@ -39,6 +39,7 @@ module HPath
,basename ,basename
,dirname ,dirname
,isParentOf ,isParentOf
,getAllParents
,stripDir ,stripDir
-- * Conversion -- * Conversion
,canonicalizePath ,canonicalizePath
@ -235,6 +236,16 @@ stripDir (MkPath p) (MkPath l) =
isParentOf :: Path b -> Path b -> Bool isParentOf :: Path b -> Path b -> Bool
isParentOf p l = isJust (stripDir p l :: Maybe (Path Rel)) isParentOf p l = isJust (stripDir p l :: Maybe (Path Rel))
getAllParents :: Path Abs -> [Path Abs]
getAllParents (MkPath p) =
case np of
(MkPath "/") -> []
_ -> dirname np : getAllParents (dirname np)
where
np = MkPath . FilePath.dropTrailingPathSeparator . FilePath.normalise $ p
-- | Extract the directory name of a path. -- | Extract the directory name of a path.
-- --
-- The following properties hold: -- The following properties hold:
@ -259,6 +270,7 @@ basename (MkPath l)
where where
rl = last . FilePath.splitPath . FilePath.dropTrailingPathSeparator $ l rl = last . FilePath.splitPath . FilePath.dropTrailingPathSeparator $ l
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Query functions -- Query functions