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

Commit392cd86

Browse files
macdicepull[bot]
authored andcommitted
Replace pgwin32_is_junction() with lstat().
Now that lstat() reports junction points with S_IFLNK/S_ISLINK(), andunlink() can unlink them, there is no need for conditional code forWindows in a few places. That was expressed by testing for WIN32 orS_ISLNK, which we can now constant-fold.The coding around pgwin32_is_junction() was a bit suspect anyway, as wenever checked for errors, and we also know that errors can be spuriouslyreported because of transient sharing violations on this OS. Thelstat()-based code has handling for that.This also reverts4fc6b6e on master only. That was done becauselstat() didn't previously work for symlinks (junction points), but nowit does.Tested-by: Andrew Dunstan <andrew@dunslane.net>Discussion:https://postgr.es/m/CA%2BhUKGLfOOeyZpm5ByVcAt7x5Pn-%3DxGRNCvgiUPVVzjFLtnY0w%40mail.gmail.com
1 parentdce57d7 commit392cd86

File tree

10 files changed

+2
-78
lines changed

10 files changed

+2
-78
lines changed

‎src/backend/commands/tablespace.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
792792
/*
793793
* Try to remove the symlink. We must however deal with the possibility
794794
* that it's a directory instead of a symlink --- this could happen during
795-
* WAL replay (see TablespaceCreateDbspace), and it is also the case on
796-
* Windows where junction points lstat() as directories.
795+
* WAL replay (see TablespaceCreateDbspace).
797796
*
798797
* Note: in the redo case, we'll return true if this final step fails;
799798
* there's no point in retrying it. Also, ENOENT should provoke no more
@@ -823,7 +822,6 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
823822
linkloc)));
824823
}
825824
}
826-
#ifdefS_ISLNK
827825
elseif (S_ISLNK(st.st_mode))
828826
{
829827
if (unlink(linkloc)<0)
@@ -836,7 +834,6 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
836834
linkloc)));
837835
}
838836
}
839-
#endif
840837
else
841838
{
842839
/* Refuse to remove anything that's not a directory or symlink */
@@ -914,7 +911,6 @@ remove_tablespace_symlink(const char *linkloc)
914911
errmsg("could not remove directory \"%s\": %m",
915912
linkloc)));
916913
}
917-
#ifdefS_ISLNK
918914
elseif (S_ISLNK(st.st_mode))
919915
{
920916
if (unlink(linkloc)<0&&errno!=ENOENT)
@@ -923,7 +919,6 @@ remove_tablespace_symlink(const char *linkloc)
923919
errmsg("could not remove symbolic link \"%s\": %m",
924920
linkloc)));
925921
}
926-
#endif
927922
else
928923
{
929924
/* Refuse to remove anything that's not a directory or symlink */

‎src/backend/replication/basebackup.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,7 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
13221322
}
13231323

13241324
/* Allow symbolic links in pg_tblspc only */
1325-
if (strcmp(path,"./pg_tblspc")==0&&
1326-
#ifndefWIN32
1327-
S_ISLNK(statbuf.st_mode)
1328-
#else
1329-
pgwin32_is_junction(pathbuf)
1330-
#endif
1331-
)
1325+
if (strcmp(path,"./pg_tblspc")==0&&S_ISLNK(statbuf.st_mode))
13321326
{
13331327
charlinkpath[MAXPGPATH];
13341328
intrllen;
@@ -1798,11 +1792,7 @@ static void
17981792
convert_link_to_directory(constchar*pathbuf,structstat*statbuf)
17991793
{
18001794
/* If symlink, write it as a directory anyway */
1801-
#ifndefWIN32
18021795
if (S_ISLNK(statbuf->st_mode))
1803-
#else
1804-
if (pgwin32_is_junction(pathbuf))
1805-
#endif
18061796
statbuf->st_mode=S_IFDIR |pg_dir_create_mode;
18071797
}
18081798

‎src/backend/storage/file/fd.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,6 @@ SyncDataDirectory(void)
33653365
*/
33663366
xlog_is_symlink= false;
33673367

3368-
#ifndefWIN32
33693368
{
33703369
structstatst;
33713370

@@ -3377,10 +3376,6 @@ SyncDataDirectory(void)
33773376
elseif (S_ISLNK(st.st_mode))
33783377
xlog_is_symlink= true;
33793378
}
3380-
#else
3381-
if (pgwin32_is_junction("pg_wal"))
3382-
xlog_is_symlink= true;
3383-
#endif
33843379

33853380
#ifdefHAVE_SYNCFS
33863381
if (recovery_init_sync_method==RECOVERY_INIT_SYNC_METHOD_SYNCFS)

‎src/backend/utils/adt/misc.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
283283
charsourcepath[MAXPGPATH];
284284
chartargetpath[MAXPGPATH];
285285
intrllen;
286-
#ifndefWIN32
287286
structstatst;
288-
#endif
289287

290288
/*
291289
* It's useful to apply this function to pg_class.reltablespace, wherein
@@ -314,10 +312,6 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
314312
* created with allow_in_place_tablespaces enabled. If a directory is
315313
* found, a relative path to the data directory is returned.
316314
*/
317-
#ifdefWIN32
318-
if (!pgwin32_is_junction(sourcepath))
319-
PG_RETURN_TEXT_P(cstring_to_text(sourcepath));
320-
#else
321315
if (lstat(sourcepath,&st)<0)
322316
{
323317
ereport(ERROR,
@@ -328,7 +322,6 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
328322

329323
if (!S_ISLNK(st.st_mode))
330324
PG_RETURN_TEXT_P(cstring_to_text(sourcepath));
331-
#endif
332325

333326
/*
334327
* In presence of a link or a junction point, return the path pointing to.

‎src/bin/pg_checksums/pg_checksums.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
384384
if (!sizeonly)
385385
scan_file(fn,segmentno);
386386
}
387-
#ifndefWIN32
388387
elseif (S_ISDIR(st.st_mode)||S_ISLNK(st.st_mode))
389-
#else
390-
elseif (S_ISDIR(st.st_mode)||pgwin32_is_junction(fn))
391-
#endif
392388
{
393389
/*
394390
* If going through the entries of pg_tblspc, we assume to operate

‎src/bin/pg_rewind/file_ops.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,7 @@ recurse_dir(const char *datadir, const char *parentpath,
431431
/* recurse to handle subdirectories */
432432
recurse_dir(datadir,path,callback);
433433
}
434-
#ifndefWIN32
435434
elseif (S_ISLNK(fst.st_mode))
436-
#else
437-
elseif (pgwin32_is_junction(fullpath))
438-
#endif
439435
{
440436
charlink_target[MAXPGPATH];
441437
intlen;

‎src/common/file_utils.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ fsync_pgdata(const char *pg_data,
7979
*/
8080
xlog_is_symlink= false;
8181

82-
#ifndefWIN32
8382
{
8483
structstatst;
8584

@@ -88,10 +87,6 @@ fsync_pgdata(const char *pg_data,
8887
elseif (S_ISLNK(st.st_mode))
8988
xlog_is_symlink= true;
9089
}
91-
#else
92-
if (pgwin32_is_junction(pg_wal))
93-
xlog_is_symlink= true;
94-
#endif
9590

9691
/*
9792
* If possible, hint to the kernel that we're soon going to fsync the data
@@ -459,27 +454,9 @@ get_dirent_type(const char *path,
459454
result=PGFILETYPE_REG;
460455
elseif (S_ISDIR(fst.st_mode))
461456
result=PGFILETYPE_DIR;
462-
#ifdefS_ISLNK
463457
elseif (S_ISLNK(fst.st_mode))
464458
result=PGFILETYPE_LNK;
465-
#endif
466459
}
467460

468-
#if defined(WIN32)&& !defined(_MSC_VER)
469-
470-
/*
471-
* If we're on native Windows (not Cygwin, which has its own POSIX
472-
* symlinks), but not using the MSVC compiler, then we're using a
473-
* readdir() emulation provided by the MinGW runtime that has no d_type.
474-
* Since the lstat() fallback code reports junction points as directories,
475-
* we need an extra system call to check if we should report them as
476-
* symlinks instead, following our convention.
477-
*/
478-
if (result==PGFILETYPE_DIR&&
479-
!look_through_symlinks&&
480-
pgwin32_is_junction(path))
481-
result=PGFILETYPE_LNK;
482-
#endif
483-
484461
returnresult;
485462
}

‎src/include/port.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ extern intpgunlink(const char *path);
284284
#if defined(WIN32)&& !defined(__CYGWIN__)
285285
externintpgsymlink(constchar*oldpath,constchar*newpath);
286286
externintpgreadlink(constchar*path,char*buf,size_tsize);
287-
externboolpgwin32_is_junction(constchar*path);
288287

289288
#definesymlink(oldpath,newpath)pgsymlink(oldpath, newpath)
290289
#definereadlink(path,buf,size)pgreadlink(path, buf, size)

‎src/include/port/win32_port.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ intsetitimer(int which, const struct itimerval *value, struct itimerval *oval
230230
*/
231231
externintpgsymlink(constchar*oldpath,constchar*newpath);
232232
externintpgreadlink(constchar*path,char*buf,size_tsize);
233-
externboolpgwin32_is_junction(constchar*path);
234233

235234
#definesymlink(oldpath,newpath)pgsymlink(oldpath, newpath)
236235
#definereadlink(path,buf,size)pgreadlink(path, buf, size)

‎src/port/dirmod.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,4 @@ pgreadlink(const char *path, char *buf, size_t size)
362362
returnr;
363363
}
364364

365-
/*
366-
* Assumes the file exists, so will return false if it doesn't
367-
* (since a nonexistent file is not a junction)
368-
*/
369-
bool
370-
pgwin32_is_junction(constchar*path)
371-
{
372-
DWORDattr=GetFileAttributes(path);
373-
374-
if (attr==INVALID_FILE_ATTRIBUTES)
375-
{
376-
_dosmaperr(GetLastError());
377-
return false;
378-
}
379-
return ((attr&FILE_ATTRIBUTE_REPARSE_POINT)==FILE_ATTRIBUTE_REPARSE_POINT);
380-
}
381365
#endif/* defined(WIN32) && !defined(__CYGWIN__) */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp