v2-0002-pg_resetwal-Improve-error-with-wrong-missing-data.patch

text/plain

Filename: v2-0002-pg_resetwal-Improve-error-with-wrong-missing-data.patch
Type: text/plain
Part: 1
Message: Re: pg_resetwal tests, logging, and docs update

Patch

Format: format-patch
Series: patch v2-0002
Subject: pg_resetwal: Improve error with wrong/missing data directory
File+
src/bin/pg_resetwal/pg_resetwal.c 4 4
From 8fee9806bfa94fc999e730d3fb55946c656e6c64 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 19 Sep 2023 15:58:49 +0200
Subject: [PATCH v2 2/7] pg_resetwal: Improve error with wrong/missing data
 directory

Run chdir() before permission check to get a less confusing error
message if the specified data directory does not exist.
---
 src/bin/pg_resetwal/pg_resetwal.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index b7885e34f3..e344c9284d 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -345,6 +345,10 @@ main(int argc, char *argv[])
 
 	get_restricted_token();
 
+	if (chdir(DataDir) < 0)
+		pg_fatal("could not change directory to \"%s\": %m",
+				 DataDir);
+
 	/* Set mask based on PGDATA permissions */
 	if (!GetDataDirectoryCreatePerm(DataDir))
 		pg_fatal("could not read permissions of directory \"%s\": %m",
@@ -352,10 +356,6 @@ main(int argc, char *argv[])
 
 	umask(pg_mode_mask);
 
-	if (chdir(DataDir) < 0)
-		pg_fatal("could not change directory to \"%s\": %m",
-				 DataDir);
-
 	/* Check that data directory matches our server version */
 	CheckDataVersion();
 
-- 
2.42.0