diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2023-11-05 21:59:04 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2023-11-05 21:59:04 +0100 |
commit | 2c7c6c417fe655ab3fd4ca7f68ec22c913a2fe80 (patch) | |
tree | cecc2286b8ca0d8e7245e8a5b0b19caf87257a03 /src | |
parent | 151ffcf6d8c1a527fa3abc27b1a13c0d43be494e (diff) | |
download | postgresql-2c7c6c417fe655ab3fd4ca7f68ec22c913a2fe80.tar.gz postgresql-2c7c6c417fe655ab3fd4ca7f68ec22c913a2fe80.zip |
More consistent behavior of GetDataDirectoryCreatePerm on Windows
On Windows, GetDataDirectoryCreatePerm() just did nothing. The way
the code in some callers is structured, this is the first function
that tries to access the data directory. So it also ends up the place
that is responsible for reporting that a data directory does not exist
or similar. Therefore, on Windows, these scenarios end up on
potentially completely different code paths.
To unify this, to make testing more consistent across platforms, have
GetDataDirectoryCreatePerm() run the stat() call on Windows as well,
even though it won't do anything with the result. That way, file
system errors are reporting to callers in the same way as on
non-Windows.
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://www.postgresql.org/message-id/15a59bca-0383-183c-9383-0446da9b87e1%40eisentraut.org
Diffstat (limited to 'src')
-rw-r--r-- | src/common/file_perm.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/common/file_perm.c b/src/common/file_perm.c index 60f88d2caf1..81464f939ca 100644 --- a/src/common/file_perm.c +++ b/src/common/file_perm.c @@ -59,12 +59,12 @@ SetDataDirectoryCreatePerm(int dataDirMode) * false is returned. * * Suppress when on Windows, because there may not be proper support for Unix-y - * file permissions. + * file permissions. But we still run stat() on the directory so that callers + * get consistent behavior for example if the directory does not exist. */ bool GetDataDirectoryCreatePerm(const char *dataDir) { -#if !defined(WIN32) && !defined(__CYGWIN__) struct stat statBuf; /* @@ -75,16 +75,12 @@ GetDataDirectoryCreatePerm(const char *dataDir) if (stat(dataDir, &statBuf) == -1) return false; +#if !defined(WIN32) && !defined(__CYGWIN__) /* Set permissions */ SetDataDirectoryCreatePerm(statBuf.st_mode); - return true; -#else /* !defined(WIN32) && !defined(__CYGWIN__) */ - /* - * On Windows, we don't have anything to do here since they don't have - * Unix-y permissions. - */ - return true; #endif + + return true; } |