LIB: remove more occurences of FilePath

This commit is contained in:
Julian Ospald 2016-04-03 03:57:11 +02:00
parent 4da3c92e5e
commit 4e75a84439
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 23 additions and 20 deletions

View File

@ -48,6 +48,7 @@ import Foreign.C.Error
import HPath
(
Path
, Abs
, Fn
)
import qualified HPath as P
@ -234,14 +235,16 @@ recreateSymlink _ _ _ = throw $ InvalidOperation "wrong input type"
-- |TODO: handle EAGAIN exception for non-blocking IO
-- |Low-level function to copy a given file to the given path. The fileMode
-- is preserved. The file is always overwritten if accessible.
copyFile' :: FilePath -> FilePath -> IO ()
copyFile' :: Path Abs -> Path Abs -> IO ()
copyFile' from to = do
fromFstatus <- getSymbolicLinkStatus from
fromContent <- BS.readFile from
fd <- System.Posix.IO.createFile to
let from' = P.fromAbs from
to' = P.fromAbs to
fromFstatus <- getSymbolicLinkStatus from'
fromContent <- BS.readFile from'
fd <- System.Posix.IO.createFile to'
(System.Posix.Files.fileMode fromFstatus)
closeFd fd
BS.writeFile to fromContent
BS.writeFile to' fromContent
-- |Copies the given file to the given file destination, overwriting it.
@ -257,7 +260,7 @@ overwriteFile from@(_ :/ RegFile {})
let from' = fullPath from
to' = fullPath to
throwSameFile from' to'
copyFile' (P.fromAbs from') (P.fromAbs to')
copyFile' from' to'
overwriteFile _ _ = throw $ InvalidOperation "wrong input type"
@ -277,7 +280,7 @@ copyFileToDir cm from@(_ :/ RegFile fn _)
case cm of
Strict -> throwFileDoesExist to'
_ -> return ()
copyFile' (P.fromAbs from') (P.fromAbs to')
copyFile' from' to'
copyFileToDir _ _ _ = throw $ InvalidOperation "wrong input type"

View File

@ -45,10 +45,6 @@ import Data.List
(
isPrefixOf
)
import Data.Maybe
(
catMaybes
)
import Data.Time.Clock.POSIX
(
POSIXTime
@ -581,22 +577,26 @@ getContents (ADirOrSym af) = readDirectoryContents (fullPath af)
getContents _ = return []
getDirsFiles' :: (FilePath -> [FilePath] -> [FilePath])
getDirsFiles' :: (Path Fn -> [Path Fn] -> [Path Fn])
-> Path Abs
-> IO [Path Fn]
getDirsFiles' filterf fp = do
dirstream <- PFD.openDirStream . P.toFilePath $ fp
let mdirs :: [FilePath] -> IO [FilePath]
let mdirs :: [Path Fn] -> IO [Path Fn]
mdirs dirs = do
-- make sure we close the directory stream in case of errors
-- TODO: more explicit error handling?
-- both the parsing and readin the stream can fail!
dir <- onException (PFD.readDirStream dirstream)
(PFD.closeDirStream dirstream)
if dir == ""
then return dirs
else mdirs (dir `filterf` dirs)
case dir of
"" -> return dirs
_ -> do
pdir <- P.parseFn dir
mdirs $ pdir `filterf` dirs
dirs <- mdirs []
PFD.closeDirStream dirstream
return $ catMaybes (fmap P.parseFn dirs)
return dirs
-- |Get all files of a given directory and return them as a List.
@ -611,9 +611,9 @@ getDirsFiles :: Path Abs -> IO [Path Fn]
getDirsFiles = getDirsFiles' insert
where
insert dir dirs = case dir of
"." -> dirs
".." -> dirs
_ -> dir : dirs
(Path ".") -> dirs
(Path "..") -> dirs
_ -> dir : dirs
-- |Gets all file information.