Thread

  1. pg_rewind: Skip vanished source files during traversal

    Ayush Tiwari <ayushtiwari.slg01@gmail.com> — 2026-05-28T06:01:16Z

    Hi,
    
    While looking at pg_rewind's source directory traversal, I noticed a small
    thing in recurse_dir() that I wanted to ask about.
    
    When lstat() fails with ENOENT, the existing comment says that this is OK
    when scanning a live source data directory, because the file may have been
    removed by the new primary:
    
        File doesn't exist anymore. This is ok, if the new primary
        is running and the file was just removed.
    
    But after that branch, the code continues and later checks fst.st_mode to
    decide whether the entry is a regular file, directory, or symlink.  Since
    lstat() failed in that case, is fst still safe to inspect?  It seems to me
    that the intended behavior might be to skip that directory entry once ENOENT
    is accepted.
    
    The attached patch adds a continue in that branch.
    
    I tested this with a small harness around traverse_datadir() and an lstat()
    shim that returns ENOENT for one directory entry.  Without the patch, the
    callback was still invoked for that entry; with the patch, it was skipped.
    
    Does this interpretation make sense, or is there a reason we should continue
    processing the entry after ENOENT?
    
    Regards,
    Ayush