aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-07 14:48:23 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-07 14:48:23 -0400
commitd9cbdf43fe6ce971d9b5a99e60a70055f67b1ed3 (patch)
tree540a849d67b0ab43c981dc4a93432743be1054b3
parent734d7e8360b09b80f943140186911d47dc5db735 (diff)
import: Fix failure of cross-device import on Windows.
As well as import, 2 other places ran "mv" manually, so changed them to use moveFile as well.
-rw-r--r--Command/Reinject.hs6
-rw-r--r--Command/SetKey.hs7
-rw-r--r--Utility/Directory.hs27
-rw-r--r--debian/changelog1
4 files changed, 28 insertions, 13 deletions
diff --git a/Command/Reinject.hs b/Command/Reinject.hs
index 2c785feb6..de7f6eb3d 100644
--- a/Command/Reinject.hs
+++ b/Command/Reinject.hs
@@ -50,11 +50,13 @@ perform src dest key = do
)
where
-- the file might be on a different filesystem,
- -- so mv is used rather than simply calling
+ -- so moveFile is used rather than simply calling
-- moveToObjectDir; disk space is also
-- checked this way.
move = getViaTmp key $ \tmp ->
- liftIO $ boolSystem "mv" [File src, File tmp]
+ liftIO $ catchBoolIO $ do
+ moveFile src tmp
+ return True
reject = const $ return "wrong file?"
cleanup :: Key -> CommandCleanup
diff --git a/Command/SetKey.hs b/Command/SetKey.hs
index 02118fb14..d5762dd8c 100644
--- a/Command/SetKey.hs
+++ b/Command/SetKey.hs
@@ -31,13 +31,14 @@ mkKey = fromMaybe (error "bad key") . file2key
perform :: FilePath -> Key -> CommandPerform
perform file key = do
- -- the file might be on a different filesystem, so mv is used
+ -- the file might be on a different filesystem, so moveFile is used
-- rather than simply calling moveAnnex; disk space is also
-- checked this way.
ok <- getViaTmp key $ \dest ->
if dest /= file
- then liftIO $
- boolSystem "mv" [File file, File dest]
+ then liftIO $ catchBoolIO $ do
+ moveFile file dest
+ return True
else return True
if ok
then next $ cleanup key
diff --git a/Utility/Directory.hs b/Utility/Directory.hs
index 7322cd85f..2d9e9c40e 100644
--- a/Utility/Directory.hs
+++ b/Utility/Directory.hs
@@ -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 e' -> (False, e')
+ Right _ -> (True, e)
+#endif
unless ok $ do
-- delete any partial
_ <- tryIO $ removeFile tmp
- rethrow
+ throwM e'
isdir f = do
r <- tryIO $ getFileStatus f
diff --git a/debian/changelog b/debian/changelog
index 5ffbcf4de..e8264a4a9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,7 @@ git-annex (5.20150618) UNRELEASED; urgency=medium
git init --shared=world.
* On linux, pass --as-needed to linker to avoid linking with unused
shared libraries including libyaml.
+ * import: Fix failure of cross-device import on Windows.
-- Joey Hess <id@joeyh.name> Thu, 02 Jul 2015 12:31:14 -0400