( )⚙ D12202 status: fix hg status race against file deletion

This is an archive of the discontinued Mercurial Phabricator instance.

status: fix hg status race against file deletion
ClosedPublic

Authored by aalekseyev on Feb 17 2022, 3:51 PM.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

aalekseyev created this revision.Feb 17 2022, 3:51 PM

This is a bug that leads to hg status wrongly saying that the whole directory is deleted even though only some of the files in it was deleted (potentially one of the ignored files, in which case the status could even be clean).
I tested it using the following command:

(mkdir r; cd r; hg init; echo 'd/x*' > .hgignore; mkdir d; touch d/x{1..10000}; hg status --config 'extensions.sparse=!' & rm d/*; wait; cd ..; rm -r r)

Without this patch, this prints "d: No such file or directory". With this patch it does not.

The condition to skip just the ENOENT errors is equivalent to the one in osutil.c (line 393). Unfortunately, I believe the pure code is still buggy: there's still the same bug at mercurial/pure/osutil.py line 62.

Alphare accepted this revision.Feb 18 2022, 5:27 AM
Alphare added a subscriber: Alphare.

Good find, thanks!

This revision is now accepted and ready to land.Feb 18 2022, 5:27 AM
This revision was automatically updated to reflect the committed changes.