From d2e5e401831867a6a184f00c88bd569aef63a6e1 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Tue, 2 Dec 2025 14:59:53 +0800 Subject: [PATCH v4 08/13] cleanup: avoid local variables shadowed by static file-scope ones in file_ops.c This commit fixes several cases in file_ops.c where local variables used names that conflicted with static variables defined at file scope. The local identifiers are renamed so they are no longer shadowed by the file- scope variables and remain unambiguous within their respective blocks. Author: Chao Li Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com --- src/bin/pg_rewind/file_ops.c | 50 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c index 55659ce201f..3867233e8a8 100644 --- a/src/bin/pg_rewind/file_ops.c +++ b/src/bin/pg_rewind/file_ops.c @@ -186,41 +186,41 @@ create_target(file_entry_t *entry) void remove_target_file(const char *path, bool missing_ok) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); - if (unlink(dstpath) != 0) + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); + if (unlink(pathbuf) != 0) { if (errno == ENOENT && missing_ok) return; pg_fatal("could not remove file \"%s\": %m", - dstpath); + pathbuf); } } void truncate_target_file(const char *path, off_t newsize) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; int fd; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); - fd = open(dstpath, O_WRONLY, pg_file_create_mode); + fd = open(pathbuf, O_WRONLY, pg_file_create_mode); if (fd < 0) pg_fatal("could not open file \"%s\" for truncation: %m", - dstpath); + pathbuf); if (ftruncate(fd, newsize) != 0) pg_fatal("could not truncate file \"%s\" to %u: %m", - dstpath, (unsigned int) newsize); + pathbuf, (unsigned int) newsize); close(fd); } @@ -228,57 +228,57 @@ truncate_target_file(const char *path, off_t newsize) static void create_target_dir(const char *path) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); - if (mkdir(dstpath, pg_dir_create_mode) != 0) + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); + if (mkdir(pathbuf, pg_dir_create_mode) != 0) pg_fatal("could not create directory \"%s\": %m", - dstpath); + pathbuf); } static void remove_target_dir(const char *path) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); - if (rmdir(dstpath) != 0) + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); + if (rmdir(pathbuf) != 0) pg_fatal("could not remove directory \"%s\": %m", - dstpath); + pathbuf); } static void create_target_symlink(const char *path, const char *link) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); - if (symlink(link, dstpath) != 0) + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); + if (symlink(link, pathbuf) != 0) pg_fatal("could not create symbolic link at \"%s\": %m", - dstpath); + pathbuf); } static void remove_target_symlink(const char *path) { - char dstpath[MAXPGPATH]; + char pathbuf[MAXPGPATH]; if (dry_run) return; - snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); - if (unlink(dstpath) != 0) + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", datadir_target, path); + if (unlink(pathbuf) != 0) pg_fatal("could not remove symbolic link \"%s\": %m", - dstpath); + pathbuf); } /* -- 2.39.5 (Apple Git-154)