Add getAllParents
This commit is contained in:
parent
3c3a2d2766
commit
3a52a9ea4b
12
src/HPath.hs
12
src/HPath.hs
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user