summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-17 16:39:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-17 16:39:30 -0400
commita020b0c25c4e7c2e14d685eac8c4d3aa0e1fef8a (patch)
treee008a967ab6ea350e97c723924fd8f95ad91d04c
parent8398b9ab4a654f3f6ec570b70229a8a0030e8ab6 (diff)
atomic file retrieval from backends
-rw-r--r--Commands.hs9
-rw-r--r--Core.hs9
-rw-r--r--Locations.hs8
-rw-r--r--TODO6
4 files changed, 22 insertions, 10 deletions
diff --git a/Commands.hs b/Commands.hs
index 8591dbf6a..05af0ab2d 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -156,13 +156,16 @@ getCmd file = notinBackend file err $ \(key, backend) -> do
showStart "get" file
g <- Annex.gitRepo
let dest = annexLocation g key
- liftIO $ createDirectoryIfMissing True (parentDir dest)
- success <- Backend.retrieveKeyFile backend key dest
+ let tmp = (annexTmpLocation g) ++ (keyFile key)
+ liftIO $ createDirectoryIfMissing True (parentDir tmp)
+ success <- Backend.retrieveKeyFile backend key tmp
if (success)
then do
+ liftIO $ renameFile tmp dest
logStatus key ValuePresent
showEndOk
- else showEndFail "get" file
+ else do
+ showEndFail "get" file
where
err = error $ "not annexed " ++ file
diff --git a/Core.hs b/Core.hs
index 27411b2e6..302e304e4 100644
--- a/Core.hs
+++ b/Core.hs
@@ -29,6 +29,8 @@ startup flags = do
shutdown :: Annex ()
shutdown = do
g <- Annex.gitRepo
+
+ -- handle pending commits
nocommit <- Annex.flagIsSet NoCommit
needcommit <- Annex.flagIsSet NeedCommit
if (needcommit && not nocommit)
@@ -36,6 +38,13 @@ shutdown = do
"git-annex log update", gitStateDir g]
else return ()
+ -- clean up any files left in the temp directory
+ let tmp = annexTmpLocation g
+ exists <- liftIO $ doesDirectoryExist tmp
+ if (exists)
+ then liftIO $ removeDirectoryRecursive $ tmp
+ else return ()
+
{- configure git to use union merge driver on state files, if it is not
- already -}
gitAttributes :: Git.Repo -> IO ()
diff --git a/Locations.hs b/Locations.hs
index 76516224c..2b0adb7ba 100644
--- a/Locations.hs
+++ b/Locations.hs
@@ -7,7 +7,8 @@ module Locations (
keyFile,
fileKey,
annexLocation,
- annexLocationRelative
+ annexLocationRelative,
+ annexTmpLocation
) where
import Data.String.Utils
@@ -36,6 +37,11 @@ annexLocation r key =
annexLocationRelative :: Git.Repo -> Key -> FilePath
annexLocationRelative r key = Git.dir r ++ "/annex/" ++ (keyFile key)
+{- .git-annex/tmp is used for temp files
+ -}
+annexTmpLocation :: Git.Repo -> FilePath
+annexTmpLocation r = (Git.workTree r) ++ "/" ++ Git.dir r ++ "/annex/tmp/"
+
{- Converts a key into a filename fragment.
-
- Escape "/" in the key name, to keep a flat tree of files and avoid
diff --git a/TODO b/TODO
index 807df32d8..410c694c2 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,6 @@
* bug: cannot "git annex ../foo" (GitRepo.relative is buggy and
git-ls-files also refuses w/o --full-name, which would need other changes)
-* bug: git annex add file is silent if file was a symlink and got replaced
- with a file. The you then git command -a, you'll check in the fil contents..
-
* --push/--pull should take a reponame and files, and push those files
to that repo; dropping them from the current repo
@@ -17,9 +14,6 @@
* Support for remote git repositories (ssh:// specifically can be made to
work, although the other end probably needs to have git-annex installed..)
-* Copy files atomically, don't leave a partial key on interrupt.
- (Fix for URL download too..)
-
* Find a way to copy a file with a progress bar, while still preserving
stat. Easiest way might be to use pv and fix up the permissions etc
after?