From 27673b0751d0402cb86d831ff72ea35af69df45d Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 26 Dec 2015 23:21:02 +0100 Subject: [PATCH] LIB: make moveFile portable --- src/IO/File.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/IO/File.hs b/src/IO/File.hs index b132020..eb5c0ec 100644 --- a/src/IO/File.hs +++ b/src/IO/File.hs @@ -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 ()