16
16
static void check_data_dir (const char * pg_data );
17
17
static void check_bin_dir (ClusterInfo * cluster );
18
18
static void validate_exec (const char * dir , const char * cmdName );
19
+ #ifdef WIN32
20
+ static int win32_check_directory_write_permissions (void );
21
+ #endif
19
22
20
23
21
24
/*
@@ -97,17 +100,11 @@ verify_directories(void)
97
100
98
101
prep_status ("Checking current, bin, and data directories" );
99
102
100
- if (access ("." , R_OK | W_OK
101
103
#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 )
109
107
#endif
110
- ) != 0 )
111
108
pg_log (PG_FATAL ,
112
109
"You must have read and write access in the current directory.\n" );
113
110
@@ -119,6 +116,32 @@ verify_directories(void)
119
116
}
120
117
121
118
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
+
122
145
/*
123
146
* check_data_dir()
124
147
*
0 commit comments