status: fix hg status race against file deletion stable 6.0.3
authorArseniy Alekseyev <aalekseyev@janestreet.com>
Thu, 17 Feb 2022 20:50:04 +0000
branchstable
changeset 48774 dcec16e799dd
parent 48748 2d6940811067
child 48775 f383129468e6
child 48794 834c938227c6
status: fix hg status race against file deletion Differential Revision: https://phab.mercurial-scm.org/D12202
rust/hg-core/src/dirstate_tree/status.rs
--- a/rust/hg-core/src/dirstate_tree/status.rs	Wed Aug 25 19:55:20 2021 -0700
+++ b/rust/hg-core/src/dirstate_tree/status.rs	Thu Feb 17 20:50:04 2022 +0000
@@ -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" {