From 3bbde223770cd9d4119502addcf3ab0074007519 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 9 May 2016 17:37:00 +0200 Subject: [PATCH] Add 'hiddenFile' to System.Posix.FilePath --- src/HPath.hs | 25 ------------------------- src/System/Posix/FilePath.hs | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/HPath.hs b/src/HPath.hs index 3a2729e..f9c4168 100644 --- a/src/HPath.hs +++ b/src/HPath.hs @@ -48,8 +48,6 @@ module HPath -- * ByteString operations ,fpToString ,userStringToFP - -- * ByteString Query functions - ,hiddenFile -- * Queries ,hasParentDir ,isFileName @@ -359,29 +357,6 @@ withFnPath :: Path Fn -> (ByteString -> IO a) -> IO a 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 diff --git a/src/System/Posix/FilePath.hs b/src/System/Posix/FilePath.hs index 6837854..61e593b 100644 --- a/src/System/Posix/FilePath.hs +++ b/src/System/Posix/FilePath.hs @@ -61,6 +61,7 @@ module System.Posix.FilePath ( , isFileName , hasParentDir , equalFilePath +, hiddenFile , fpToString , userStringToFP @@ -587,6 +588,26 @@ equalFilePath p1 p2 = f p1 == f p2 where 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