ensure that direct mode file is not modified while generating its key

This commit is contained in:
Joey Hess 2012-12-29 15:32:29 -04:00
parent c0ffa8f6f0
commit 92287f6905

View file

@ -73,24 +73,36 @@ lockDown file = do
ingest :: KeySource -> Annex (Maybe Key) ingest :: KeySource -> Annex (Maybe Key)
ingest source = do ingest source = do
backend <- chooseBackend $ keyFilename source backend <- chooseBackend $ keyFilename source
genKey source backend >>= go
where
go Nothing = do
liftIO $ nukeFile $ contentLocation source
return Nothing
go (Just (key, _)) = do
ifM isDirect ifM isDirect
( do ( do
updateCache key $ keyFilename source mstat <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus $ keyFilename source
void $ addAssociatedFile key $ keyFilename source k <- genKey source backend
liftIO $ allowWrite $ keyFilename source godirect k (toCache =<< mstat)
liftIO $ nukeFile $ contentLocation source , go =<< genKey source backend
, do )
where
go (Just (key, _)) = do
handle (undo (keyFilename source) key) $ handle (undo (keyFilename source) key) $
moveAnnex key $ contentLocation source moveAnnex key $ contentLocation source
liftIO $ nukeFile $ keyFilename source liftIO $ nukeFile $ keyFilename source
)
return $ Just key return $ Just key
go Nothing = failure
godirect (Just (key, _)) (Just cache) =
ifM (compareCache (keyFilename source) $ Just cache)
( do
writeCache key cache
void $ addAssociatedFile key $ keyFilename source
liftIO $ allowWrite $ keyFilename source
liftIO $ nukeFile $ contentLocation source
return $ Just key
, failure
)
godirect _ _ = failure
failure = do
liftIO $ nukeFile $ contentLocation source
return Nothing
perform :: FilePath -> CommandPerform perform :: FilePath -> CommandPerform
perform file = perform file =