Use latest posix-paths

Pending upstream PR.
This commit is contained in:
Julian Ospald 2016-04-16 19:12:23 +02:00
parent 7e8c745e35
commit f1875da780
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 4 additions and 78 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "3rdparty/posix-paths"]
path = 3rdparty/posix-paths
url = https://github.com/hasufell/posix-paths.git

1
3rdparty/posix-paths vendored Submodule

@ -0,0 +1 @@
Subproject commit 71db05b99c4b4630f9fe182a466153877ac3420e

View File

@ -56,7 +56,6 @@ module HPath
,dropTrailingPathSeparator ,dropTrailingPathSeparator
,fpToString ,fpToString
,joinPath ,joinPath
,normalise
,splitDirectories ,splitDirectories
,splitFileName ,splitFileName
,splitPath ,splitPath
@ -66,10 +65,7 @@ module HPath
,hiddenFile ,hiddenFile
-- * Queries -- * Queries
,hasParentDir ,hasParentDir
,isAbsolute
,isFileName ,isFileName
,isRelative
,isValid
-- * String based functions -- * String based functions
) )
where 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. -- |Uses UTF-8 decoding to convert the bytestring into a String.
fpToString :: ByteString -> String fpToString :: ByteString -> String
fpToString = toString fpToString = toString
@ -541,18 +478,3 @@ isFileName filepath =
not (BS.null filepath) && not (BS.null filepath) &&
not (nullByte `BS.elem` 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