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

Commitaf7738f

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 parent895243d commitaf7738f

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

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

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

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

617634
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp