diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-29 15:32:29 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-29 15:32:29 -0400 |
commit | 2cc59ae3a1b568f01185bfe251274a4f952f21d8 (patch) | |
tree | a5a6b1f43d32e87a085cd09434050e7727406d8b /Command | |
parent | efa302a457cdd305be6d75182e88dffad50cc300 (diff) |
ensure that direct mode file is not modified while generating its key
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Add.hs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/Command/Add.hs b/Command/Add.hs index b3181cfd7..25548a973 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -73,24 +73,36 @@ lockDown file = do ingest :: KeySource -> Annex (Maybe Key) ingest source = do backend <- chooseBackend $ keyFilename source - genKey source backend >>= go + ifM isDirect + ( do + mstat <- liftIO $ catchMaybeIO $ getSymbolicLinkStatus $ keyFilename source + k <- genKey source backend + godirect k (toCache =<< mstat) + , go =<< genKey source backend + ) where - go Nothing = do - liftIO $ nukeFile $ contentLocation source - return Nothing go (Just (key, _)) = do - ifM isDirect + handle (undo (keyFilename source) key) $ + moveAnnex key $ contentLocation source + liftIO $ nukeFile $ keyFilename source + return $ Just key + go Nothing = failure + + godirect (Just (key, _)) (Just cache) = + ifM (compareCache (keyFilename source) $ Just cache) ( do - updateCache key $ keyFilename source + writeCache key cache void $ addAssociatedFile key $ keyFilename source liftIO $ allowWrite $ keyFilename source liftIO $ nukeFile $ contentLocation source - , do - handle (undo (keyFilename source) key) $ - moveAnnex key $ contentLocation source - liftIO $ nukeFile $ keyFilename source + return $ Just key + , failure ) - return $ Just key + godirect _ _ = failure + + failure = do + liftIO $ nukeFile $ contentLocation source + return Nothing perform :: FilePath -> CommandPerform perform file = |