summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-19 16:46:15 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-19 16:56:07 -0400
commitf35a84fac750d8e246f3fcd1f25054951eff8b7e (patch)
tree3042423df86514fa9b7118d15564d3431a4d7d83
parent71cb04bb6d7d787181f158cad15a67628b0b4402 (diff)
use a different tmp file when fscking remote data
Since the content might be symlinked into place, it's not appropriate to use withTmp here.
-rw-r--r--Command/Fsck.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/Command/Fsck.hs b/Command/Fsck.hs
index 77e189f43..9d856ce88 100644
--- a/Command/Fsck.hs
+++ b/Command/Fsck.hs
@@ -58,13 +58,13 @@ perform key file backend numcopies = check
{- To fsck a remote, the content is retrieved to a tmp file,
- and checked locally. -}
performRemote :: Key -> FilePath -> Backend -> Maybe Int -> Remote -> CommandPerform
-performRemote key file backend numcopies remote = withTmp key $ \tmpfile -> do
+performRemote key file backend numcopies remote = do
v <- Remote.hasKey remote key
case v of
Left err -> do
showNote err
stop
- Right True -> do
+ Right True -> withtmp $ \tmpfile -> do
copied <- Remote.retrieveKeyFile remote key True tmpfile
if copied then go True (Just tmpfile) else go False Nothing
Right False -> go False Nothing
@@ -75,6 +75,14 @@ performRemote key file backend numcopies remote = withTmp key $ \tmpfile -> do
, checkBackendRemote backend key remote localcopy
, checkKeyNumCopies key file numcopies
]
+ withtmp a = do
+ pid <- liftIO getProcessID
+ t <- fromRepo gitAnnexTmpDir
+ let tmp = t </> "fsck" ++ show pid ++ "." ++ keyFile key
+ liftIO $ createDirectoryIfMissing True t
+ let cleanup = liftIO $ catch (removeFile tmp) (const $ return ())
+ cleanup
+ cleanup `after` a tmp
{- To fsck a bare repository, fsck each key in the location log. -}
withBarePresentKeys :: (Key -> CommandStart) -> CommandSeek