Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit081a551

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 thatplatform.Backpatch to 9.1 where this check was added.
1 parente399eb7 commit081a551

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
staticvoidcheck_data_dir(constchar*pg_data);
1717
staticvoidcheck_bin_dir(ClusterInfo*cluster);
1818
staticvoidvalidate_exec(constchar*dir,constchar*cmdName);
19+
#ifdefWIN32
20+
staticintwin32_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
#ifndefWIN32
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+
#ifdefWIN32
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+
staticint
128+
win32_check_directory_write_permissions(void)
129+
{
130+
intfd;
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+
returnunlink(GLOBALS_DUMP_FILE);
141+
}
142+
#endif
143+
144+
122145
/*
123146
* check_data_dir()
124147
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp