Patchwork D12202: status: fix hg status race against file deletion

login
register
mail settings
Submitter phabricator
Date Feb. 17, 2022, 8:51 p.m.
Message ID <differential-rev-PHID-DREV-odrg56smvdll6gnhjbqw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50539/
State New
Headers show

Comments

phabricator - Feb. 17, 2022, 8:51 p.m.
aalekseyev created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12202

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/status.rs

CHANGE DETAILS




To: aalekseyev, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/dirstate_tree/status.rs b/rust/hg-core/src/dirstate_tree/status.rs
--- a/rust/hg-core/src/dirstate_tree/status.rs
+++ b/rust/hg-core/src/dirstate_tree/status.rs
@@ -713,7 +713,17 @@ 
         let mut results = Vec::new();
         for entry in path.read_dir()? {
             let entry = entry?;
-            let metadata = entry.metadata()?;
+            let metadata = match entry.metadata() {
+                Ok(v) => v,
+                Err(e) => {
+                    // race with file deletion?
+                    if e.kind() == std::io::ErrorKind::NotFound {
+                        continue;
+                    } else {
+                        return Err(e);
+                    }
+                }
+            };
             let name = get_bytes_from_os_string(entry.file_name());
             // FIXME don't do this when cached
             if name == b".hg" {