From b7cd5ba857da84c4ad88e4d8987e22c4071d31c1 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 26 Jan 2020 20:00:46 +0100 Subject: [PATCH] Add takeAllParents --- hpath-filepath/src/System/Posix/FilePath.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hpath-filepath/src/System/Posix/FilePath.hs b/hpath-filepath/src/System/Posix/FilePath.hs index cc9d27e..9a41802 100644 --- a/hpath-filepath/src/System/Posix/FilePath.hs +++ b/hpath-filepath/src/System/Posix/FilePath.hs @@ -59,6 +59,7 @@ module System.Posix.FilePath ( , splitPath , joinPath , splitDirectories +, takeAllParents -- * Trailing slash functions , hasTrailingPathSeparator @@ -500,6 +501,21 @@ splitDirectories x splitter = filter (not . BS.null) . BS.split pathSeparator +-- |Get all parents of a path. +-- +-- >>> takeAllParents "/abs/def/dod" +-- ["/abs/def","/abs","/"] +-- >>> takeAllParents "/foo" +-- ["/"] +-- >>> takeAllParents "/" +-- [] +takeAllParents :: RawFilePath -> [RawFilePath] +takeAllParents p + | np == BS.singleton pathSeparator = [] + | otherwise = takeDirectory np : takeAllParents (takeDirectory np) + where + np = normalise p + ------------------------ -- Trailing slash functions