summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-06-09 15:24:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-06-09 15:24:05 -0400
commitfb31e247cb0dea919824f5e3bd9086eef382e4bc (patch)
tree722c4dd581ae7d05083418b36c632ac841acef63
parent6cd15cc11bf66dc0db15dcb339d61e9fc3628f89 (diff)
Avoid leaving behind .tmp files when failing in some cases, including importing files to a disk that is full.
-rw-r--r--Utility/Tmp.hs21
-rw-r--r--debian/changelog2
-rw-r--r--doc/bugs/import_leaves_stray___96__.tmp__96___files_if_interrupted.mdwn3
3 files changed, 19 insertions, 7 deletions
diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs
index 0dc9f2c05..bed30bb4d 100644
--- a/Utility/Tmp.hs
+++ b/Utility/Tmp.hs
@@ -25,13 +25,20 @@ type Template = String
- then moving it into place. The temp file is stored in the same
- directory as the final file to avoid cross-device renames. -}
viaTmp :: (FilePath -> String -> IO ()) -> FilePath -> String -> IO ()
-viaTmp a file content = do
- let (dir, base) = splitFileName file
- createDirectoryIfMissing True dir
- (tmpfile, handle) <- openTempFile dir (base ++ ".tmp")
- hClose handle
- a tmpfile content
- rename tmpfile file
+viaTmp a file content = bracket setup cleanup use
+ where
+ (dir, base) = splitFileName file
+ template = base ++ ".tmp"
+ setup = do
+ createDirectoryIfMissing True dir
+ openTempFile dir template
+ cleanup (tmpfile, handle) = do
+ _ <- tryIO $ hClose handle
+ tryIO $ removeFile tmpfile
+ use (tmpfile, handle) = do
+ hClose handle
+ a tmpfile content
+ rename tmpfile file
{- Runs an action with a tmp file located in the system's tmp directory
- (or in "." if there is none) then removes the file. -}
diff --git a/debian/changelog b/debian/changelog
index 7749953c1..612864faf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
git-annex (5.20140607) UNRELEASED; urgency=medium
* Ignore setsid failures.
+ * Avoid leaving behind .tmp files when failing in some cases, including
+ importing files to a disk that is full.
-- Joey Hess <joeyh@debian.org> Mon, 09 Jun 2014 14:44:09 -0400
diff --git a/doc/bugs/import_leaves_stray___96__.tmp__96___files_if_interrupted.mdwn b/doc/bugs/import_leaves_stray___96__.tmp__96___files_if_interrupted.mdwn
index 658a5a5e1..50037246d 100644
--- a/doc/bugs/import_leaves_stray___96__.tmp__96___files_if_interrupted.mdwn
+++ b/doc/bugs/import_leaves_stray___96__.tmp__96___files_if_interrupted.mdwn
@@ -7,3 +7,6 @@ These files should be removed when import detects that its has no more space to
### What version of git-annex are you using? On what operating system?
git-annex 5.20140517.4 in Ubuntu 12.04.
+
+> The ".tmp" means this dropping is left by viaTmp, and I see why.
+> [[fixed|done]] --[[Joey]]