1616static void check_data_dir (const char * pg_data );
1717static void check_bin_dir (ClusterInfo * cluster );
1818static 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