tweak
This commit is contained in:
parent
7ee300a47f
commit
1bae56e4a0
1 changed files with 17 additions and 14 deletions
|
@ -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
|
- 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
|
- temporary location, and its writable bits are removed. It could still be
|
||||||
- written to by a process that already has it open for writing. -}
|
- written to by a process that already has it open for writing. -}
|
||||||
lockDown :: FilePath -> Annex FilePath
|
lockDown :: FilePath -> Annex KeySource
|
||||||
lockDown file = do
|
lockDown file = do
|
||||||
liftIO $ preventWrite file
|
liftIO $ preventWrite file
|
||||||
tmp <- fromRepo gitAnnexTmpDir
|
tmp <- fromRepo gitAnnexTmpDir
|
||||||
|
@ -59,24 +59,27 @@ lockDown file = do
|
||||||
let tmpfile = tmp </> "add" ++ show pid ++ "." ++ takeFileName file
|
let tmpfile = tmp </> "add" ++ show pid ++ "." ++ takeFileName file
|
||||||
liftIO $ nukeFile tmpfile
|
liftIO $ nukeFile tmpfile
|
||||||
liftIO $ createLink file tmpfile
|
liftIO $ createLink file tmpfile
|
||||||
return tmpfile
|
return $ KeySource { keyFilename = file , contentLocation = tmpfile }
|
||||||
|
|
||||||
{- Moves the file into the annex. -}
|
{- Moves a locked down file into the annex. -}
|
||||||
ingest :: FilePath -> Annex (Maybe Key)
|
ingest :: KeySource -> Annex (Maybe Key)
|
||||||
ingest file = do
|
ingest source = do
|
||||||
tmpfile <- lockDown file
|
backend <- chooseBackend $ keyFilename source
|
||||||
let source = KeySource { keyFilename = file, contentLocation = tmpfile }
|
genKey source backend >>= go
|
||||||
backend <- chooseBackend file
|
|
||||||
genKey source backend >>= go tmpfile
|
|
||||||
where
|
where
|
||||||
go _ Nothing = return Nothing
|
go Nothing = do
|
||||||
go tmpfile (Just (key, _)) = do
|
liftIO $ nukeFile $ contentLocation source
|
||||||
handle (undo file key) $ moveAnnex key tmpfile
|
return Nothing
|
||||||
liftIO $ nukeFile file
|
go (Just (key, _)) = do
|
||||||
|
handle (undo (keyFilename source) key) $
|
||||||
|
moveAnnex key $ contentLocation source
|
||||||
|
liftIO $ nukeFile $ keyFilename source
|
||||||
return $ Just key
|
return $ Just key
|
||||||
|
|
||||||
perform :: FilePath -> CommandPerform
|
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.
|
{- 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. -}
|
- This can be called before or after the symlink is in place. -}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue