LIB: make moveFile portable

This commit is contained in:
Julian Ospald 2015-12-26 23:21:02 +01:00
parent 35e6f5df82
commit 27673b0751
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -35,7 +35,9 @@ import Control.Applicative
)
import Control.Exception
(
throw
handle
, throw
, SomeException(..)
)
import Control.Monad
(
@ -396,7 +398,6 @@ renameFile af (ValFN fn) = do
renameFile _ _ = return ()
-- TODO: this is not portable for cross-device links!
-- |Move a given file to the given target directory.
moveFile :: AnchoredFile FileInfo -- ^ file to move
-> AnchoredFile FileInfo -- ^ base target directory
@ -406,7 +407,10 @@ moveFile from to@(_ :/ Dir {}) = do
to' = fullPath to </> (name . file $ from)
throwFileDoesExist to'
throwSameFile from' to'
rename from' to'
handle (\(SomeException e) -> do
easyCopy Strict from to
easyDelete from
) $ rename from' to'
moveFile _ _ = return ()