assistant: Fix a crash when a small file is deleted immediately after being created

git add will fail if the file got deleted in the meantime. And since it was
queued, there was a window until the queue flushed where a deletion of the
file would cause a crash.

Instead, reuse Command.Add.addFile, which sha1 hashes the file itself
immediately, and then queues the index update. Ignore exceptions that will
happen if the file got deleted already.

Sponsored-by: k0ld on Patreon
This commit is contained in:
Joey Hess 2023-06-19 12:09:18 -04:00
parent 553962eb47
commit 217a6abb19
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 10 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{- git-annex assistant commit thread
-
- Copyright 2012-2021 Joey Hess <id@joeyh.name>
- Copyright 2012-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -38,6 +38,7 @@ import qualified Annex
import Utility.InodeCache
import qualified Database.Keys
import qualified Command.Sync
import qualified Command.Add
import Config.GitConfig
import Utility.Tuple
import Utility.Metered
@ -303,8 +304,10 @@ handleAdds lockdowndir havelsof largefilematcher annexdotfiles delayadd cs = ret
f = toRawFilePath (changeFile change)
addsmall [] = noop
addsmall toadd = liftAnnex $ Annex.Queue.addCommand [] "add"
[ Param "--force", Param "--"] (map changeFile toadd)
addsmall toadd = liftAnnex $ void $ tryIO $
forM (map (toRawFilePath . changeFile) toadd) $ \f ->
Command.Add.addFile Command.Add.Small f
=<< liftIO (R.getSymbolicLinkStatus f)
{- Avoid overhead of re-injesting a renamed unlocked file, by
- examining the other Changes to see if a removed file has the

View file

@ -91,6 +91,8 @@ git-annex (10.20230408) UNRELEASED; urgency=medium
* config: Added the --show-origin and --for-file options.
* config: Support annex.numcopies and annex.mincopies.
* Fix display when run with -J1.
* assistant: Fix a crash when a small file is deleted immediately after
being created.
-- Joey Hess <id@joeyh.name> Sat, 08 Apr 2023 13:57:18 -0400

View file

@ -67,3 +67,5 @@ Committer crashed: user error (xargs ["-0","git","--git-dir=.git","--work-tree=.
# End of transcript or log.
"""]]
> [[fixed|done]] --[[Joey]]