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

Commit0da7cf6

Browse files
committed
Fix multiple bugs in tablespace symlink removal.
Don't try to examine S_ISLNK(st.st_mode) after a failed lstat().It's undefined.Also, if the lstat() reported ENOENT, we do not wish that to be a harderror, but the code might nonetheless treat it as one (giving an entirelymisleading error message, too) depending on luck-of-the-draw as to whatS_ISLNK() returned.Don't throw error for ENOENT from rmdir(), either. (We're not reallyexpecting ENOENT because we just stat'd the file successfully; butif we're going to allow ENOENT in the symlink code path, surely thedirectory code path should too.)Generate an appropriate errcode for its-the-wrong-type-of-file complaints.(ERRCODE_SYSTEM_ERROR doesn't seem appropriate, and failing to writeerrcode() around it certainly doesn't work, and not writing an errcodeat all is not per project policy.)Valgrind noticed the undefined S_ISLNK result; the other problems emergedwhile reading the code in the area.All of this appears to have been introduced in8f15f74.Back-patch to 9.5 where that commit appeared.
1 parent6929e7f commit0da7cf6

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

‎src/backend/commands/tablespace.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,26 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
773773
remove_symlink:
774774
linkloc=pstrdup(linkloc_with_version_dir);
775775
get_parent_directory(linkloc);
776-
if (lstat(linkloc,&st)==0&&S_ISDIR(st.st_mode))
776+
if (lstat(linkloc,&st)<0)
777+
{
778+
intsaved_errno=errno;
779+
780+
ereport(redo ?LOG : (saved_errno==ENOENT ?WARNING :ERROR),
781+
(errcode_for_file_access(),
782+
errmsg("could not stat file \"%s\": %m",
783+
linkloc)));
784+
}
785+
elseif (S_ISDIR(st.st_mode))
777786
{
778787
if (rmdir(linkloc)<0)
779-
ereport(redo ?LOG :ERROR,
788+
{
789+
intsaved_errno=errno;
790+
791+
ereport(redo ?LOG : (saved_errno==ENOENT ?WARNING :ERROR),
780792
(errcode_for_file_access(),
781793
errmsg("could not remove directory \"%s\": %m",
782794
linkloc)));
795+
}
783796
}
784797
#ifdefS_ISLNK
785798
elseif (S_ISLNK(st.st_mode))
@@ -799,7 +812,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
799812
{
800813
/* Refuse to remove anything that's not a directory or symlink */
801814
ereport(redo ?LOG :ERROR,
802-
(ERRCODE_SYSTEM_ERROR,
815+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
803816
errmsg("\"%s\" is not a directory or symbolic link",
804817
linkloc)));
805818
}
@@ -851,7 +864,7 @@ remove_tablespace_symlink(const char *linkloc)
851864
{
852865
structstatst;
853866

854-
if (lstat(linkloc,&st)!=0)
867+
if (lstat(linkloc,&st)<0)
855868
{
856869
if (errno==ENOENT)
857870
return;
@@ -863,10 +876,10 @@ remove_tablespace_symlink(const char *linkloc)
863876
if (S_ISDIR(st.st_mode))
864877
{
865878
/*
866-
* This will fail if the directory isn't empty, but not
867-
*if it's ajunction point.
879+
* This will fail if the directory isn't empty, but not if it's a
880+
* junction point.
868881
*/
869-
if (rmdir(linkloc)<0)
882+
if (rmdir(linkloc)<0&&errno!=ENOENT)
870883
ereport(ERROR,
871884
(errcode_for_file_access(),
872885
errmsg("could not remove directory \"%s\": %m",
@@ -878,15 +891,16 @@ remove_tablespace_symlink(const char *linkloc)
878891
if (unlink(linkloc)<0&&errno!=ENOENT)
879892
ereport(ERROR,
880893
(errcode_for_file_access(),
881-
errmsg("could not remove symbolic link \"%s\": %m",
894+
errmsg("could not remove symbolic link \"%s\": %m",
882895
linkloc)));
883896
}
884897
#endif
885898
else
886899
{
887900
/* Refuse to remove anything that's not a directory or symlink */
888901
ereport(ERROR,
889-
(errmsg("\"%s\" is not a directory or symbolic link",
902+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
903+
errmsg("\"%s\" is not a directory or symbolic link",
890904
linkloc)));
891905
}
892906
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp