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

Commit6340565

Browse files
committed
Fix tablespace creation WAL replay to work on Windows.
The code segment that removes the old symlink (if present) wasn't cluedinto the fact that on Windows, symlinks are junction points which haveto be removed with rmdir().Backpatch to 9.0, where the failing code was introduced.MauMau, reviewed by Muhammad Asif Naeem and Amit Kapila
1 parentaf7004e commit6340565

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

‎src/backend/commands/tablespace.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
538538
char*linkloc=palloc(OIDCHARS+OIDCHARS+1);
539539
char*location_with_version_dir=palloc(strlen(location)+1+
540540
strlen(TABLESPACE_VERSION_DIRECTORY)+1);
541+
structstatst;
541542

542543
sprintf(linkloc,"pg_tblspc/%u",tablespaceoid);
543544
sprintf(location_with_version_dir,"%s/%s",location,
@@ -564,8 +565,6 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
564565

565566
if (InRecovery)
566567
{
567-
structstatst;
568-
569568
/*
570569
* Our theory for replaying a CREATE is to forcibly drop the target
571570
* subdirectory if present, and then recreate it. This may be
@@ -599,14 +598,32 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
599598
location_with_version_dir)));
600599
}
601600

602-
/* Remove old symlink in recovery, in case it points to the wrong place */
601+
/*
602+
* In recovery, remove old symlink, in case it points to the wrong place.
603+
*
604+
* On Windows, junction points act like directories so we must be able to
605+
* apply rmdir; in general it seems best to make this code work like the
606+
* symlink removal code in destroy_tablespace_directories, except that
607+
* failure to remove is always an ERROR.
608+
*/
603609
if (InRecovery)
604610
{
605-
if (unlink(linkloc)<0&&errno!=ENOENT)
606-
ereport(ERROR,
607-
(errcode_for_file_access(),
608-
errmsg("could not remove symbolic link \"%s\": %m",
609-
linkloc)));
611+
if (lstat(linkloc,&st)==0&&S_ISDIR(st.st_mode))
612+
{
613+
if (rmdir(linkloc)<0)
614+
ereport(ERROR,
615+
(errcode_for_file_access(),
616+
errmsg("could not remove directory \"%s\": %m",
617+
linkloc)));
618+
}
619+
else
620+
{
621+
if (unlink(linkloc)<0&&errno!=ENOENT)
622+
ereport(ERROR,
623+
(errcode_for_file_access(),
624+
errmsg("could not remove symbolic link \"%s\": %m",
625+
linkloc)));
626+
}
610627
}
611628

612629
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp