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
1 changed files with 12 additions and 0 deletions

View File

@ -39,6 +39,7 @@ module HPath
,basename
,dirname
,isParentOf
,getAllParents
,stripDir
-- * Conversion
,canonicalizePath
@ -235,6 +236,16 @@ stripDir (MkPath p) (MkPath l) =
isParentOf :: Path b -> Path b -> Bool
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.
--
-- The following properties hold:
@ -259,6 +270,7 @@ basename (MkPath l)
where
rl = last . FilePath.splitPath . FilePath.dropTrailingPathSeparator $ l
--------------------------------------------------------------------------------
-- Query functions