Skip to content

Commit 2c7c6c4

Browse files
committed
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
1 parent 151ffcf commit 2c7c6c4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/common/file_perm.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ SetDataDirectoryCreatePerm(int dataDirMode)
5959
* false is returned.
6060
*
6161
* Suppress when on Windows, because there may not be proper support for Unix-y
62-
* file permissions.
62+
* file permissions. But we still run stat() on the directory so that callers
63+
* get consistent behavior for example if the directory does not exist.
6364
*/
6465
bool
6566
GetDataDirectoryCreatePerm(const char *dataDir)
6667
{
67-
#if !defined(WIN32) && !defined(__CYGWIN__)
6868
struct stat statBuf;
6969

7070
/*
@@ -75,16 +75,12 @@ GetDataDirectoryCreatePerm(const char *dataDir)
7575
if (stat(dataDir, &statBuf) == -1)
7676
return false;
7777

78+
#if !defined(WIN32) && !defined(__CYGWIN__)
7879
/* Set permissions */
7980
SetDataDirectoryCreatePerm(statBuf.st_mode);
80-
return true;
81-
#else /* !defined(WIN32) && !defined(__CYGWIN__) */
82-
/*
83-
* On Windows, we don't have anything to do here since they don't have
84-
* Unix-y permissions.
85-
*/
86-
return true;
8781
#endif
82+
83+
return true;
8884
}
8985

9086

0 commit comments

Comments
 (0)