From bda4926d4662920404e26360118cb41d74e2eee3 Mon Sep 17 00:00:00 2001 From: ganyang Date: Thu, 17 Nov 2022 20:00:16 +0800 Subject: [PATCH] add tablespace symlink check --- src/gausskernel/optimizer/commands/tablespace.cpp | 11 ++++++++++- src/test/regress/input/tablespace.source | 5 +++++ src/test/regress/output/tablespace_1.source | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/optimizer/commands/tablespace.cpp b/src/gausskernel/optimizer/commands/tablespace.cpp index 6336e1818..9a3254348 100644 --- a/src/gausskernel/optimizer/commands/tablespace.cpp +++ b/src/gausskernel/optimizer/commands/tablespace.cpp @@ -1293,7 +1293,16 @@ static void create_tablespace_directories(const char* location, const Oid tables ereport(ERROR, (errcode_for_file_access(), errmsg("could not remove symbolic link \"%s\": %m", linkloc))); } } - + /* do not support symbolic link -> symbolic link */ + struct stat st; + if (lstat(location, &st) == 0) { + if (S_ISLNK(st.st_mode)) { + ereport(ERROR, + (errmodule(MOD_TBLSPC), + errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("location \"%s\" is symbolic link", location))); + } + } /* * Create the symlink under PGDATA */ diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source index 28e014800..338166234 100644 --- a/src/test/regress/input/tablespace.source +++ b/src/test/regress/input/tablespace.source @@ -136,3 +136,8 @@ end; -- Should succeed DROP TABLESPACE testspace; + +-- symlink location +\! mkdir -p @testtablespace@/symlink/sym1 +\! ln -s @testtablespace@/symlink/sym1 @testtablespace@/symlink/sym2 +CREATE TABLESPACE test_symlink LOCATION '@testtablespace@/symlink/sym2'; \ No newline at end of file diff --git a/src/test/regress/output/tablespace_1.source b/src/test/regress/output/tablespace_1.source index e64200792..1d507edb8 100644 --- a/src/test/regress/output/tablespace_1.source +++ b/src/test/regress/output/tablespace_1.source @@ -267,3 +267,8 @@ ERROR: DROP TABLESPACE cannot run inside a transaction block end; -- Should succeed DROP TABLESPACE testspace; +-- symlink location +\! mkdir -p @testtablespace@/symlink/sym1 +\! ln -s @testtablespace@/symlink/sym1 @testtablespace@/symlink/sym2 +CREATE TABLESPACE test_symlink LOCATION '@testtablespace@/symlink/sym2'; +ERROR: location "@testtablespace@/symlink/sym2" is symbolic link