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

Commit84520f9

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 parent7d1a0f5 commit84520f9

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
@@ -544,6 +544,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
544544
char*linkloc=palloc(OIDCHARS+OIDCHARS+1);
545545
char*location_with_version_dir=palloc(strlen(location)+1+
546546
strlen(TABLESPACE_VERSION_DIRECTORY)+1);
547+
structstatst;
547548

548549
sprintf(linkloc,"pg_tblspc/%u",tablespaceoid);
549550
sprintf(location_with_version_dir,"%s/%s",location,
@@ -570,8 +571,6 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
570571

571572
if (InRecovery)
572573
{
573-
structstatst;
574-
575574
/*
576575
* Our theory for replaying a CREATE is to forcibly drop the target
577576
* subdirectory if present, and then recreate it. This may be more
@@ -605,14 +604,32 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
605604
location_with_version_dir)));
606605
}
607606

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

618635
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp