summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-15 13:38:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-08-15 13:38:05 -0400
commit6c36d87ceff8b792e1f1a0f6b324e79173cc923c (patch)
treecf686e3db00d4a571412bbadfc91231accac16bc
parentcfaa1a8fcf522ef3f51bbd2a057e7ab571bcdd1b (diff)
direct: Avoid leaving file content in misctemp if interrupted.
-rw-r--r--Annex/Direct.hs7
-rw-r--r--Annex/ReplaceFile.hs13
-rw-r--r--debian/changelog1
-rw-r--r--doc/bugs/direct_command_leaves_repository_inconsistent_if_interrupted.mdwn2
4 files changed, 14 insertions, 9 deletions
diff --git a/Annex/Direct.hs b/Annex/Direct.hs
index 374599369..7b91cc342 100644
--- a/Annex/Direct.hs
+++ b/Annex/Direct.hs
@@ -353,11 +353,8 @@ toDirectGen k f = do
void $ addAssociatedFile k f
modifyContent loc $ do
thawContent loc
- replaceFileOr f
- (liftIO . moveFile loc)
- $ \tmp -> do -- rollback
- liftIO (moveFile tmp loc)
- freezeContent loc
+ liftIO (replaceFileFrom loc f)
+ `catchIO` (\_ -> freezeContent loc)
fromdirect loc = do
replaceFile f $
liftIO . void . copyFileExternal loc
diff --git a/Annex/ReplaceFile.hs b/Annex/ReplaceFile.hs
index 8cb0cc6da..9700d4b60 100644
--- a/Annex/ReplaceFile.hs
+++ b/Annex/ReplaceFile.hs
@@ -39,7 +39,12 @@ replaceFileOr file action rollback = do
return tmpfile
go tmpfile = do
action tmpfile
- liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
- fallback tmpfile _ = do
- createDirectoryIfMissing True $ parentDir file
- moveFile tmpfile file
+ liftIO $ replaceFileFrom tmpfile file
+
+replaceFileFrom :: FilePath -> FilePath -> IO ()
+replaceFileFrom src dest = go `catchIO` fallback
+ where
+ go = moveFile src dest
+ fallback _ = do
+ createDirectoryIfMissing True $ parentDir dest
+ go
diff --git a/debian/changelog b/debian/changelog
index b1d53a841..eaa36b362 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -35,6 +35,7 @@ git-annex (5.20140718) UNRELEASED; urgency=medium
subdirectory in the key name.
* S3, Glacier, WebDAV: Fix bug that prevented accessing the creds
when the repository was configured with encryption=shared embedcreds=yes.
+ * direct: Avoid leaving file content in misctemp if interrupted.
-- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2014 14:41:26 -0400
diff --git a/doc/bugs/direct_command_leaves_repository_inconsistent_if_interrupted.mdwn b/doc/bugs/direct_command_leaves_repository_inconsistent_if_interrupted.mdwn
index 0d81c6778..c19db9727 100644
--- a/doc/bugs/direct_command_leaves_repository_inconsistent_if_interrupted.mdwn
+++ b/doc/bugs/direct_command_leaves_repository_inconsistent_if_interrupted.mdwn
@@ -41,3 +41,5 @@ Similar issues and discussions:
* [[forum/Cleaning_up_after_aborted_sync_in_direct_mode/]]
* [[bugs/failure_to_return_to_indirect_mode_on_usb/]]
* [[forum/git-status_typechange_in_direct_mode/]]
+
+[[!meta title="git annex lock --force deletes only copy of content after interrupted switch to direct mode"]