From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Thu, 28 May 2026 00:00:00 +0000
Subject: [PATCH v1] pg_rewind: Skip vanished source files during traversal

When pg_rewind traverses a live source data directory, a file can
vanish between readdir() and lstat().  The code already treats ENOENT as
acceptable in that case, but then continued to inspect fst.st_mode.
Since lstat() failed, fst does not contain valid metadata, so pg_rewind
could invoke the traversal callback, recurse, or try readlink() for an
entry that should have been skipped.

Continue immediately after ENOENT so the entry is ignored as intended.
---
 src/bin/pg_rewind/file_ops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c
index acd8fa758fd..b23887614f6 100644
--- a/src/bin/pg_rewind/file_ops.c
+++ b/src/bin/pg_rewind/file_ops.c
@@ -435,6 +435,7 @@ recurse_dir(const char *datadir, const char *parentpath,
 				 *
 				 * TODO: But complain if we're processing the target dir!
 				 */
+				continue;
 			}
 			else
 				pg_fatal("could not stat file \"%s\": %m",
-- 
2.43.0
