Run chdir() before permission check to get a less confusing error
message if the specified data directory does not exist.
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://www.postgresql.org/message-id/flat/
0f3ab4a1-ae80-56e8-3426-
6b4a02507687@eisentraut.org
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",
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();