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

Commitfa56aa2

Browse files
macdiceadunstan
authored andcommitted
Make unlink() work for junction points on Windows.
To support harmonization of Windows and Unix code, teach our unlink()wrapper that junction points need to be unlinked with rmdir() onWindows.Tested-by: Andrew Dunstan <andrew@dunslane.net>Discussion:https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com(cherry picked from commitf357233)Author: Thomas Munro <tmunro@postgresql.org>Author: Alexandra Wang <alexandra.wang.oss@gmail.com>
1 parent5c0b758 commitfa56aa2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

‎src/port/dirmod.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ int
9999
pgunlink(constchar*path)
100100
{
101101
intloops=0;
102+
structstatst;
103+
104+
/*
105+
* This function might be called for a regular file or for a junction
106+
* point (which we use to emulate symlinks). The latter must be unlinked
107+
* with rmdir() on Windows. Before we worry about any of that, let's see
108+
* if we can unlink directly, since that's expected to be the most common
109+
* case.
110+
*/
111+
if (unlink(path)==0)
112+
return0;
113+
if (errno!=EACCES)
114+
return-1;
115+
116+
/*
117+
* EACCES is reported for many reasons including unlink() of a junction
118+
* point. Check if that's the case so we can redirect to rmdir().
119+
*
120+
* Note that by checking only once, we can't cope with a path that changes
121+
* from regular file to junction point underneath us while we're retrying
122+
* due to sharing violations, but that seems unlikely. We could perhaps
123+
* prevent that by holding a file handle ourselves across the lstat() and
124+
* the retry loop, but that seems like over-engineering for now.
125+
*/
126+
if (lstat(path,&st)<0)
127+
return-1;
102128

103129
/*
104130
* We need to loop because even though PostgreSQL uses flags that allow
@@ -107,7 +133,7 @@ pgunlink(const char *path)
107133
* someone else to close the file, as the caller might be holding locks
108134
* and blocking other backends.
109135
*/
110-
while (unlink(path))
136+
while ((S_ISLNK(st.st_mode) ?rmdir(path) :unlink(path))<0)
111137
{
112138
if (errno!=EACCES)
113139
return-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp