fix overwrite race with git-annex add of annex symlink

In the unlikely case where git-annex add is run on an annex symlink that
is not already added, and while it's processing it, the annex symlink is
overwritten with something else, avoid git-annex overwriting that with
the symlink again.

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2022-06-14 13:56:17 -04:00
parent dd6dec4eb1
commit 5ef79125ad
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 14 additions and 4 deletions

View file

@ -17,6 +17,7 @@ module Annex.Ingest (
finishIngestUnlocked,
cleanOldKeys,
addLink,
addSymlink,
makeLink,
addUnlocked,
CheckGitIgnore(..),

View file

@ -181,10 +181,19 @@ start o si file addunlockedmatcher = do
_ -> add
fixuplink key =
starting "add" (ActionItemTreeFile file) si $
addingExistingLink file key $ do
liftIO $ removeFile (fromRawFilePath file)
addLink (checkGitIgnoreOption o) file key Nothing
addingExistingLink file key $
withOtherTmp $ \tmp -> do
let tmpf = fromRawFilePath tmp </> fromRawFilePath file
liftIO $ moveFile (fromRawFilePath file) tmpf
ifM (isSymbolicLink <$> liftIO (getSymbolicLinkStatus tmpf))
( do
liftIO $ removeFile tmpf
addSymlink file key Nothing
next $ cleanup key =<< inAnnex key
, do
liftIO $ moveFile tmpf (fromRawFilePath file)
next $ return True
)
fixuppointer key =
starting "add" (ActionItemTreeFile file) si $
addingExistingLink file key $ do