Skip to content

Commit 081a551

Browse files
committed
In pg_upgrade on Windows, check if the directory is writable by actually
creating and removing a file because access() doesn't work on that platform. Backpatch to 9.1 where this check was added.
1 parent e399eb7 commit 081a551

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

contrib/pg_upgrade/exec.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
static void check_data_dir(const char *pg_data);
1717
static void check_bin_dir(ClusterInfo *cluster);
1818
static void validate_exec(const char *dir, const char *cmdName);
19+
#ifdef WIN32
20+
static int win32_check_directory_write_permissions(void);
21+
#endif
1922

2023

2124
/*
@@ -97,17 +100,11 @@ verify_directories(void)
97100

98101
prep_status("Checking current, bin, and data directories");
99102

100-
if (access(".", R_OK | W_OK
101103
#ifndef WIN32
102-
103-
/*
104-
* Do a directory execute check only on Unix because execute permission on
105-
* NTFS means "can execute scripts", which we don't care about. Also, X_OK
106-
* is not defined in the Windows API.
107-
*/
108-
| X_OK
104+
if (access(".", R_OK | W_OK | X_OK) != 0)
105+
#else
106+
if (win32_check_directory_write_permissions() != 0)
109107
#endif
110-
) != 0)
111108
pg_log(PG_FATAL,
112109
"You must have read and write access in the current directory.\n");
113110

@@ -119,6 +116,32 @@ verify_directories(void)
119116
}
120117

121118

119+
#ifdef WIN32
120+
/*
121+
* win32_check_directory_write_permissions()
122+
*
123+
* access() on WIN32 can't check directory permissions, so we have to
124+
* optionally create, then delete a file to check.
125+
* http://msdn.microsoft.com/en-us/library/1w06ktdy%28v=vs.80%29.aspx
126+
*/
127+
static int
128+
win32_check_directory_write_permissions(void)
129+
{
130+
int fd;
131+
132+
/*
133+
* We open a file we would normally create anyway. We do this even in
134+
* 'check' mode, which isn't ideal, but this is the best we can do.
135+
*/
136+
if ((fd = open(GLOBALS_DUMP_FILE, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) < 0)
137+
return -1;
138+
close(fd);
139+
140+
return unlink(GLOBALS_DUMP_FILE);
141+
}
142+
#endif
143+
144+
122145
/*
123146
* check_data_dir()
124147
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy