From 22ddeeadccacda60d010913491bbc9f63b68b2dc Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 18 Jan 2020 18:43:55 +0100 Subject: [PATCH] Add isSpecialDirectoryEntry --- hpath-filepath/src/System/Posix/FilePath.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hpath-filepath/src/System/Posix/FilePath.hs b/hpath-filepath/src/System/Posix/FilePath.hs index dfe3d5d..40a09c6 100644 --- a/hpath-filepath/src/System/Posix/FilePath.hs +++ b/hpath-filepath/src/System/Posix/FilePath.hs @@ -73,6 +73,7 @@ module System.Posix.FilePath ( , isAbsolute , isValid , makeValid +, isSpecialDirectoryEntry , isFileName , hasParentDir , hiddenFile @@ -724,6 +725,21 @@ makeValid path | otherwise = BS.map (\x -> if x == _nul then _underscore else x) path +-- | Is a FilePath valid, i.e. could you create a file like it? +-- +-- >>> isSpecialDirectoryEntry "." +-- True +-- >>> isSpecialDirectoryEntry ".." +-- True +-- >>> isSpecialDirectoryEntry "/random_ path:*" +-- False +isSpecialDirectoryEntry :: RawFilePath -> Bool +isSpecialDirectoryEntry filepath + | BS.pack [_period, _period] == filepath = True + | BS.pack [_period] == filepath = True + | otherwise = False + + -- | Is the given path a valid filename? This includes -- "." and "..". --