From f1875da78036225675c5783cf2053388f04cd837 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 16 Apr 2016 19:12:23 +0200 Subject: [PATCH] Use latest posix-paths Pending upstream PR. --- .gitmodules | 3 ++ 3rdparty/posix-paths | 1 + src/HPath.hs | 78 -------------------------------------------- 3 files changed, 4 insertions(+), 78 deletions(-) create mode 100644 .gitmodules create mode 160000 3rdparty/posix-paths diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..3445f6a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "3rdparty/posix-paths"] + path = 3rdparty/posix-paths + url = https://github.com/hasufell/posix-paths.git diff --git a/3rdparty/posix-paths b/3rdparty/posix-paths new file mode 160000 index 0000000..71db05b --- /dev/null +++ b/3rdparty/posix-paths @@ -0,0 +1 @@ +Subproject commit 71db05b99c4b4630f9fe182a466153877ac3420e diff --git a/src/HPath.hs b/src/HPath.hs index 330ea88..1eceb61 100644 --- a/src/HPath.hs +++ b/src/HPath.hs @@ -56,7 +56,6 @@ module HPath ,dropTrailingPathSeparator ,fpToString ,joinPath - ,normalise ,splitDirectories ,splitFileName ,splitPath @@ -66,10 +65,7 @@ module HPath ,hiddenFile -- * Queries ,hasParentDir - ,isAbsolute ,isFileName - ,isRelative - ,isValid -- * String based functions ) where @@ -418,65 +414,6 @@ nullByte = _nul --- |Normalise a file. --- --- >>> normalise "/file/\\test////" --- "/file/\\test/" --- >>> normalise "/file/./test" --- "/file/test" --- >>> normalise "/test/file/../bob/fred/" --- "/test/file/../bob/fred/" --- >>> normalise "../bob/fred/" --- "../bob/fred/" --- >>> normalise "./bob/fred/" --- "bob/fred/" --- >>> normalise "./bob////.fred/./...///./..///#." --- "bob/.fred/.../../#." --- >>> normalise "." --- "." --- >>> normalise "./" --- "./" --- >>> normalise "./." --- "./" --- >>> normalise "/./" --- "/" --- >>> normalise "/" --- "/" --- >>> normalise "bob/fred/." --- "bob/fred/" --- >>> normalise "//home" --- "/home" -normalise :: ByteString -> ByteString -normalise filepath = - result `BS.append` - (if addPathSeparator - then BS.singleton pathSeparator - else BS.empty) - where - result = let n = f filepath - in if BS.null n - then BS.singleton _period - else n - addPathSeparator = isDirPath filepath && - not (hasTrailingPathSeparator' result) - isDirPath xs = hasTrailingPathSeparator' xs - || not (BS.null xs) && BS.last xs == _period - && hasTrailingPathSeparator' (BS.init xs) - f = joinPath . dropDots . propSep . splitDirectories - propSep :: [ByteString] -> [ByteString] - propSep (x:xs) - | BS.all (== pathSeparator) x = BS.singleton pathSeparator : xs - | otherwise = x : xs - propSep [] = [] - dropDots :: [ByteString] -> [ByteString] - dropDots = filter (BS.singleton _period /=) - hasTrailingPathSeparator' :: RawFilePath -> Bool - hasTrailingPathSeparator' x - | BS.null x = False - | otherwise = isPathSeparator $ BS.last x - - - -- |Uses UTF-8 decoding to convert the bytestring into a String. fpToString :: ByteString -> String fpToString = toString @@ -541,18 +478,3 @@ isFileName filepath = not (BS.null filepath) && not (nullByte `BS.elem` filepath) - --- | Is a FilePath valid, i.e. could you create a file like it? --- --- >>> isValid "" --- False --- >>> isValid "\0" --- False --- >>> isValid "/random_ path:*" --- True -isValid :: RawFilePath -> Bool -isValid filepath - | BS.null filepath = False - | _nul `BS.elem` filepath = False - | otherwise = True -