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
|
,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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user