use InodeCache to avoid races in import from directory special remote
This does not avoid all possible races, but it does avoid all likely ones, and is demonstratably better than git's own handling of races where files get modified at the same time as it's updating the working tree. The main thing this won't detect are not unlikely races where part of a file gets changed while it's being copied and then the file is restored to its original condition before the modification check. No, it's more likely that the limitations of checking inode, size, and mtime won't detect certian modifications, involving eg mmapped files.
This commit is contained in:
parent
51fc969b66
commit
3cd19fb4d0
3 changed files with 91 additions and 28 deletions
|
@ -233,12 +233,14 @@ downloadImport remote importtreeconfig importablecontents = do
|
|||
(k:_) -> return $ Just (loc, k)
|
||||
[] -> checkDiskSpaceToGet tmpkey Nothing $
|
||||
withTmp tmpkey $ \tmpfile ->
|
||||
Remote.retrieveExportWithContentIdentifier ia loc cid tmpfile (ingestkey loc tmpfile) p >>= \case
|
||||
Just k -> do
|
||||
recordcidkey cidmap db cid k
|
||||
logStatus k InfoPresent
|
||||
logChange k (Remote.uuid remote) InfoPresent
|
||||
return $ Just (loc, k)
|
||||
Remote.retrieveExportWithContentIdentifier ia loc cid tmpfile (mkkey loc tmpfile) p >>= \case
|
||||
Just k -> tryNonAsync (moveAnnex k tmpfile) >>= \case
|
||||
Right True -> do
|
||||
recordcidkey cidmap db cid k
|
||||
logStatus k InfoPresent
|
||||
logChange k (Remote.uuid remote) InfoPresent
|
||||
return $ Just (loc, k)
|
||||
_ -> return Nothing
|
||||
Nothing -> return Nothing
|
||||
where
|
||||
-- TODO progress bar
|
||||
|
@ -246,7 +248,7 @@ downloadImport remote importtreeconfig importablecontents = do
|
|||
ia = Remote.importActions remote
|
||||
tmpkey = importKey cid sz
|
||||
|
||||
ingestkey loc tmpfile = do
|
||||
mkkey loc tmpfile = do
|
||||
f <- fromRepo $ fromTopFilePath $ locworktreefilename loc
|
||||
backend <- chooseBackend f
|
||||
let ks = KeySource
|
||||
|
@ -254,12 +256,7 @@ downloadImport remote importtreeconfig importablecontents = do
|
|||
, contentLocation = tmpfile
|
||||
, inodeCache = Nothing
|
||||
}
|
||||
genKey ks backend >>= \case
|
||||
Nothing -> return Nothing
|
||||
Just (k, _) ->
|
||||
tryNonAsync (moveAnnex k tmpfile) >>= \case
|
||||
Right True -> return (Just k)
|
||||
_ -> return Nothing
|
||||
fmap fst <$> genKey ks backend
|
||||
|
||||
locworktreefilename loc = asTopFilePath $ case importtreeconfig of
|
||||
ImportTree -> fromImportLocation loc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue