summaryrefslogtreecommitdiff
path: root/src/Utility/Directory.hs
diff options
context:
space:
mode:
authorJoey Hess2015-12-15 21:08:22 -0400
committerJoey Hess2015-12-15 21:08:22 -0400
commit47a2b72bed3770d3dfb26c4142479c436a11ce55 (patch)
tree3d67f32c91338193a21aadb26f0d001d5cec9670 /src/Utility/Directory.hs
parent571318218c5598ad841cc3dff73c9fee2c7216ef (diff)
Merged Utility changes from git-annex.
Diffstat (limited to 'src/Utility/Directory.hs')
-rw-r--r--src/Utility/Directory.hs31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/Utility/Directory.hs b/src/Utility/Directory.hs
index 7322cd85..fae33b5c 100644
--- a/src/Utility/Directory.hs
+++ b/src/Utility/Directory.hs
@@ -13,7 +13,6 @@ module Utility.Directory where
import System.IO.Error
import System.Directory
import Control.Monad
-import Control.Monad.IfElse
import System.FilePath
import Control.Applicative
import Control.Concurrent
@@ -25,10 +24,11 @@ import Prelude
import qualified System.Win32 as Win32
#else
import qualified System.Posix as Posix
+import Utility.SafeCommand
+import Control.Monad.IfElse
#endif
import Utility.PosixFiles
-import Utility.SafeCommand
import Utility.Tmp
import Utility.Exception
import Utility.Monad
@@ -107,21 +107,32 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
onrename (Left e)
| isPermissionError e = rethrow
| isDoesNotExistError e = rethrow
- | otherwise = do
- -- copyFile is likely not as optimised as
- -- the mv command, so we'll use the latter.
- -- But, mv will move into a directory if
- -- dest is one, which is not desired.
- whenM (isdir dest) rethrow
- viaTmp mv dest ""
+ | otherwise = viaTmp mv dest ""
where
rethrow = throwM e
+
mv tmp _ = do
+ -- copyFile is likely not as optimised as
+ -- the mv command, so we'll use the command.
+ --
+ -- But, while Windows has a "mv", it does not seem very
+ -- reliable, so use copyFile there.
+#ifndef mingw32_HOST_OS
+ -- If dest is a directory, mv would move the file
+ -- into it, which is not desired.
+ whenM (isdir dest) rethrow
ok <- boolSystem "mv" [Param "-f", Param src, Param tmp]
+ let e' = e
+#else
+ r <- tryIO $ copyFile src tmp
+ let (ok, e') = case r of
+ Left err -> (False, err)
+ Right _ -> (True, e)
+#endif
unless ok $ do
-- delete any partial
_ <- tryIO $ removeFile tmp
- rethrow
+ throwM e'
isdir f = do
r <- tryIO $ getFileStatus f