diff options
Diffstat (limited to 'src/bin/pg_rewind/file_ops.c')
-rw-r--r-- | src/bin/pg_rewind/file_ops.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c index 705383d184f..f491ed7f5cc 100644 --- a/src/bin/pg_rewind/file_ops.c +++ b/src/bin/pg_rewind/file_ops.c @@ -29,7 +29,6 @@ static int dstfd = -1; static char dstpath[MAXPGPATH] = ""; -static void remove_target_file(const char *path); static void create_target_dir(const char *path); static void remove_target_dir(const char *path); static void create_target_symlink(const char *path, const char *link); @@ -134,7 +133,7 @@ remove_target(file_entry_t *entry) break; case FILE_TYPE_REGULAR: - remove_target_file(entry->path); + remove_target_file(entry->path, false); break; case FILE_TYPE_SYMLINK: @@ -165,8 +164,12 @@ create_target(file_entry_t *entry) } } -static void -remove_target_file(const char *path) +/* + * Remove a file from target data directory. If missing_ok is true, it + * is fine for the target file to not exist. + */ +void +remove_target_file(const char *path, bool missing_ok) { char dstpath[MAXPGPATH]; @@ -175,8 +178,13 @@ remove_target_file(const char *path) snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir_target, path); if (unlink(dstpath) != 0) + { + if (errno == ENOENT && missing_ok) + return; + pg_fatal("could not remove file \"%s\": %s\n", dstpath, strerror(errno)); + } } void |