Add 'hiddenFile' to System.Posix.FilePath

This commit is contained in:
Julian Ospald 2016-05-09 17:37:00 +02:00
parent 3da8533b48
commit 3bbde22377
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 21 additions and 25 deletions

View File

@ -48,8 +48,6 @@ module HPath
-- * ByteString operations -- * ByteString operations
,fpToString ,fpToString
,userStringToFP ,userStringToFP
-- * ByteString Query functions
,hiddenFile
-- * Queries -- * Queries
,hasParentDir ,hasParentDir
,isFileName ,isFileName
@ -359,29 +357,6 @@ withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a
withFnPath (MkPath p) action = action p withFnPath (MkPath p) action = action p
--------------------------------------------------------------------------------
-- ByteString Query functions
-- | Whether the file is a hidden file.
--
-- >>> hiddenFile (MkPath ".foo")
-- True
-- >>> hiddenFile (MkPath "..foo.bar")
-- True
-- >>> hiddenFile (MkPath "...")
-- True
-- >>> hiddenFile (MkPath "dod")
-- False
-- >>> hiddenFile (MkPath "dod.bar")
-- False
hiddenFile :: Path Fn -> Bool
hiddenFile (MkPath fp)
| fp == BS.pack [_period, _period] = False
| fp == BS.pack [_period] = False
| otherwise = BS.pack [extSeparator]
`BS.isPrefixOf` fp
------------------------ ------------------------
-- ByteString helpers -- ByteString helpers

View File

@ -61,6 +61,7 @@ module System.Posix.FilePath (
, isFileName , isFileName
, hasParentDir , hasParentDir
, equalFilePath , equalFilePath
, hiddenFile
, fpToString , fpToString
, userStringToFP , userStringToFP
@ -587,6 +588,26 @@ equalFilePath p1 p2 = f p1 == f p2
where where
f x = dropTrailingPathSeparator $ normalise x f x = dropTrailingPathSeparator $ normalise x
-- | Whether the file is a hidden file.
--
-- >>> hiddenFile ".foo"
-- True
-- >>> hiddenFile "..foo.bar"
-- True
-- >>> hiddenFile "..."
-- True
-- >>> hiddenFile "dod"
-- False
-- >>> hiddenFile "dod.bar"
-- False
hiddenFile :: RawFilePath -> Bool
hiddenFile fp
| fp == BS.pack [_period, _period] = False
| fp == BS.pack [_period] = False
| otherwise = BS.pack [extSeparator]
`BS.isPrefixOf` fp
------------------------ ------------------------
-- conversion -- conversion