get rid of racy addLink

The remaining callers all did not rely on it checking gitignore, so were
easy to convert.

They were susceptable to the same overwrite race as add and fix,
although less likely to have it and a narrower window than add's race.

Command.Rekey in passing got an unncessary call to removeFile deleted.
addSymlink handles deleting any existing worktree file.
This commit is contained in:
Joey Hess 2022-06-14 14:40:55 -04:00
parent 7ace804d8e
commit 78a3d44ea0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 15 additions and 47 deletions

View file

@ -30,9 +30,7 @@ start = startUnused "addunused" perform
perform :: Key -> CommandPerform
perform key = next $ do
logStatus key InfoPresent
-- Ignore the usual git ignores because the user has explictly
-- asked to add these files.
addLink (CheckGitIgnore False) file key Nothing
addSymlink file key Nothing
return True
where
file = "unused." <> keyFile key

View file

@ -476,13 +476,13 @@ addWorkTree _ addunlockedmatcher u url file key mtmp = case mtmp of
maybeShowJSON $ JSONChunk [("key", serializeKey key)]
setUrlPresent key url
logChange key u InfoPresent
ifM (addAnnexedFile noci addunlockedmatcher file key mtmp)
ifM (addAnnexedFile addunlockedmatcher file key mtmp)
( do
when (isJust mtmp) $
logStatus key InfoPresent
, maybe noop (\tmp -> pruneTmpWorkDirBefore tmp (liftIO . removeWhenExistsWith R.removeLink)) mtmp
)
-- git does not need to check ignores, because that has already
-- been done, as witnessed by the CannAddFile.
noci = CheckGitIgnore False

View file

@ -60,8 +60,7 @@ start si file key = ifM (isJust <$> isAnnexLink file)
perform :: RawFilePath -> Key -> CommandPerform
perform file key = do
lockdown =<< calcRepo (gitAnnexLocation key)
addLink (CheckGitIgnore False) file key
=<< withTSDelta (liftIO . genInodeCache file)
addSymlink file key =<< withTSDelta (liftIO . genInodeCache file)
next $ return True
where
lockdown obj = do

View file

@ -123,8 +123,7 @@ cleanup file newkey = do
ifM (isJust <$> isAnnexLink file)
( do
-- Update symlink to use the new key.
liftIO $ removeFile (fromRawFilePath file)
addLink (CheckGitIgnore False) file newkey Nothing
addSymlink file newkey Nothing
, do
mode <- liftIO $ catchMaybeIO $ fileMode <$> R.getFileStatus file
liftIO $ whenM (isJust <$> isPointerFile file) $