aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2015-06-26 15:53:13 -0400
committerRobert Haas <rhaas@postgresql.org>2015-06-26 15:53:13 -0400
commit8f15f74a44f68f9cb3a644786d3c732a5eeb237a (patch)
treeb95601c38396e998300f14ccdd91f5beaa2480fd /src/backend/access/transam/xlog.c
parentc66bc72e8a1318e43ea657ffa3798fa95f491650 (diff)
downloadpostgresql-8f15f74a44f68f9cb3a644786d3c732a5eeb237a.tar.gz
postgresql-8f15f74a44f68f9cb3a644786d3c732a5eeb237a.zip
Be more conservative about removing tablespace "symlinks".
Don't apply rmtree(), which will gleefully remove an entire subtree, and don't even apply unlink() unless it's symlink or a directory, the only things that we expect to find. Amit Kapila, with minor tweaks by me, per extensive discussions involving Andrew Dunstan, Fujii Masao, and Heikki Linnakangas, at least some of whom also reviewed the code.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 4e37ad3e21a..7830b47c8d1 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -38,6 +38,7 @@
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
#include "catalog/pg_database.h"
+#include "commands/tablespace.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/bgwriter.h"
@@ -6074,7 +6075,6 @@ StartupXLOG(void)
if (read_tablespace_map(&tablespaces))
{
ListCell *lc;
- struct stat st;
foreach(lc, tablespaces)
{
@@ -6085,27 +6085,9 @@ StartupXLOG(void)
/*
* Remove the existing symlink if any and Create the symlink
- * under PGDATA. We need to use rmtree instead of rmdir as
- * the link location might contain directories or files
- * corresponding to the actual path. Some tar utilities do
- * things that way while extracting symlinks.
+ * under PGDATA.
*/
- if (lstat(linkloc, &st) == 0 && S_ISDIR(st.st_mode))
- {
- if (!rmtree(linkloc, true))
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not remove directory \"%s\": %m",
- linkloc)));
- }
- else
- {
- if (unlink(linkloc) < 0 && errno != ENOENT)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not remove symbolic link \"%s\": %m",
- linkloc)));
- }
+ remove_tablespace_symlink(linkloc);
if (symlink(ti->path, linkloc) < 0)
ereport(ERROR,