diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-15 22:06:59 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-15 22:06:59 -0400 |
commit | 1bae56e4a09533b777b8c2b58c551a11e36749de (patch) | |
tree | 96fc539080d67cd3a5b8fc95cab16b20a42d8366 /Command/Add.hs | |
parent | 7ee300a47fe8a35019ae26e1dc787a136f53213c (diff) |
tweak
Diffstat (limited to 'Command/Add.hs')
-rw-r--r-- | Command/Add.hs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Command/Add.hs b/Command/Add.hs index ccdff67ec..323d1ed1e 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -50,7 +50,7 @@ start file = notBareRepo $ ifAnnexed file fixup add - to prevent it from being modified in between. It's hard linked into a - temporary location, and its writable bits are removed. It could still be - written to by a process that already has it open for writing. -} -lockDown :: FilePath -> Annex FilePath +lockDown :: FilePath -> Annex KeySource lockDown file = do liftIO $ preventWrite file tmp <- fromRepo gitAnnexTmpDir @@ -59,24 +59,27 @@ lockDown file = do let tmpfile = tmp </> "add" ++ show pid ++ "." ++ takeFileName file liftIO $ nukeFile tmpfile liftIO $ createLink file tmpfile - return tmpfile + return $ KeySource { keyFilename = file , contentLocation = tmpfile } -{- Moves the file into the annex. -} -ingest :: FilePath -> Annex (Maybe Key) -ingest file = do - tmpfile <- lockDown file - let source = KeySource { keyFilename = file, contentLocation = tmpfile } - backend <- chooseBackend file - genKey source backend >>= go tmpfile +{- Moves a locked down file into the annex. -} +ingest :: KeySource -> Annex (Maybe Key) +ingest source = do + backend <- chooseBackend $ keyFilename source + genKey source backend >>= go where - go _ Nothing = return Nothing - go tmpfile (Just (key, _)) = do - handle (undo file key) $ moveAnnex key tmpfile - liftIO $ nukeFile file + go Nothing = do + liftIO $ nukeFile $ contentLocation source + return Nothing + go (Just (key, _)) = do + handle (undo (keyFilename source) key) $ + moveAnnex key $ contentLocation source + liftIO $ nukeFile $ keyFilename source return $ Just key perform :: FilePath -> CommandPerform -perform file = maybe stop (\key -> next $ cleanup file key True) =<< ingest file +perform file = + maybe stop (\key -> next $ cleanup file key True) + =<< ingest =<< lockDown file {- On error, put the file back so it doesn't seem to have vanished. - This can be called before or after the symlink is in place. -} |