LIB: add more useful pattern synonyms
This commit is contained in:
parent
464e65d574
commit
3bd201f1b6
@ -96,6 +96,7 @@ import System.FilePath
|
|||||||
, equalFilePath
|
, equalFilePath
|
||||||
, isAbsolute
|
, isAbsolute
|
||||||
, joinPath
|
, joinPath
|
||||||
|
, pathSeparator
|
||||||
, splitDirectories
|
, splitDirectories
|
||||||
, takeFileName
|
, takeFileName
|
||||||
, (</>)
|
, (</>)
|
||||||
@ -287,6 +288,19 @@ sfile f@(Socket {}) = (True, f)
|
|||||||
sfile f = (False, f)
|
sfile f = (False, f)
|
||||||
|
|
||||||
|
|
||||||
|
invalidFileName :: FileName -> (Bool, FileName)
|
||||||
|
invalidFileName "" = (True, "")
|
||||||
|
invalidFileName "." = (True, ".")
|
||||||
|
invalidFileName ".." = (True, "..")
|
||||||
|
invalidFileName fn = (elem pathSeparator fn, fn)
|
||||||
|
|
||||||
|
|
||||||
|
-- |Matches on invalid filesnames, such as ".", ".." and anything
|
||||||
|
-- that contains a path separator.
|
||||||
|
pattern InvFN <- (invalidFileName -> (True,_))
|
||||||
|
-- |Opposite of `InvFN`.
|
||||||
|
pattern ValFN f <- (invalidFileName -> (False, f))
|
||||||
|
|
||||||
-- |Matches on symlinks (pointing to anything) or regular files.
|
-- |Matches on symlinks (pointing to anything) or regular files.
|
||||||
pattern SARegFile <- (saregfile -> (True, _))
|
pattern SARegFile <- (saregfile -> (True, _))
|
||||||
pattern SRegFile <- (sregfile -> (True, _))
|
pattern SRegFile <- (sregfile -> (True, _))
|
||||||
|
@ -406,9 +406,7 @@ executeFile _ _ = return Nothing
|
|||||||
|
|
||||||
|
|
||||||
createFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
createFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
||||||
createFile _ "" = return ()
|
createFile _ InvFN = return ()
|
||||||
createFile _ "." = return ()
|
|
||||||
createFile _ ".." = return ()
|
|
||||||
createFile (SADir td) fn = do
|
createFile (SADir td) fn = do
|
||||||
let fullp = fullPath td </> fn
|
let fullp = fullPath td </> fn
|
||||||
throwFileDoesExist fullp
|
throwFileDoesExist fullp
|
||||||
@ -417,13 +415,11 @@ createFile (SADir td) fn = do
|
|||||||
|
|
||||||
|
|
||||||
createDir :: AnchoredFile FileInfo -> FileName -> IO ()
|
createDir :: AnchoredFile FileInfo -> FileName -> IO ()
|
||||||
createDir _ "" = return ()
|
createDir (SADir td) (ValFN fn) = do
|
||||||
createDir _ "." = return ()
|
|
||||||
createDir _ ".." = return ()
|
|
||||||
createDir (SADir td) fn = do
|
|
||||||
let fullp = fullPath td </> fn
|
let fullp = fullPath td </> fn
|
||||||
throwDirDoesExist fullp
|
throwDirDoesExist fullp
|
||||||
createDirectory fullp newFilePerms
|
createDirectory fullp newFilePerms
|
||||||
|
createDir _ _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -435,15 +431,13 @@ createDir (SADir td) fn = do
|
|||||||
|
|
||||||
renameFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
renameFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
||||||
renameFile (_ :/ Failed {}) _ = return ()
|
renameFile (_ :/ Failed {}) _ = return ()
|
||||||
renameFile _ "" = return ()
|
renameFile af (ValFN fn) = do
|
||||||
renameFile _ "." = return ()
|
|
||||||
renameFile _ ".." = return ()
|
|
||||||
renameFile af fn = do
|
|
||||||
let fromf = fullPath af
|
let fromf = fullPath af
|
||||||
tof = anchor af </> fn
|
tof = anchor af </> fn
|
||||||
throwFileDoesExist tof
|
throwFileDoesExist tof
|
||||||
throwSameFile fromf tof
|
throwSameFile fromf tof
|
||||||
rename fromf tof
|
rename fromf tof
|
||||||
|
renameFile _ _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user