Use latest posix-paths
Pending upstream PR.
This commit is contained in:
parent
7e8c745e35
commit
f1875da780
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal 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
1
3rdparty/posix-paths
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 71db05b99c4b4630f9fe182a466153877ac3420e
|
78
src/HPath.hs
78
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user