Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c013e6

Browse files
committed
pg_basebackup: Fix cross-platform tablespace relocation.
Specifically, when pg_basebackup is invoked with -Tx=y, don't error out if x could plausibly be an absolute path either on Windows or on non-Windows systems. We don't know whether the remote system is running the same OS as the local system, so it's not appropriate to assume that our local rule about absolute pathnames is the same as the rule on the remote system. Patch by me, reviewed by Tom Lane, Andrew Dunstan, and Davinder Singh. Discussion: http://postgr.es/m/CA+TgmoY+jC3YiskomvYKDPK3FbrmsDU7_8+wMHt02HOdJeRb0g@mail.gmail.com
1 parent 10eaa97 commit 5c013e6

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,22 @@ tablespace_list_append(const char *arg)
342342
pg_fatal("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
343343

344344
/*
345-
* This check isn't absolutely necessary. But all tablespaces are created
346-
* with absolute directories, so specifying a non-absolute path here would
347-
* just never match, possibly confusing users. It's also good to be
348-
* consistent with the new_dir check.
345+
* All tablespaces are created with absolute directories, so specifying a
346+
* non-absolute path here would just never match, possibly confusing users.
347+
* Since we don't know whether the remote side is Windows or not, and it
348+
* might be different than the local side, permit any path that could be
349+
* absolute under either set of rules.
350+
*
351+
* (There is little practical risk of confusion here, because someone
352+
* running entirely on Linux isn't likely to have a relative path that
353+
* begins with a backslash or something that looks like a drive
354+
* specification. If they do, and they also incorrectly believe that
355+
* a relative path is acceptable here, we'll silently fail to warn them
356+
* of their mistake, and the -T option will just not get applied, same
357+
* as if they'd specified -T for a nonexistent tablespace.)
349358
*/
350-
if (!is_absolute_path(cell->old_dir))
359+
if (!is_nonwindows_absolute_path(cell->old_dir) &&
360+
!is_windows_absolute_path(cell->old_dir))
351361
pg_fatal("old directory is not an absolute path in tablespace mapping: %s",
352362
cell->old_dir);
353363

src/include/port.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,32 @@ extern void get_parent_directory(char *path);
7878
extern char **pgfnames(const char *path);
7979
extern void pgfnames_cleanup(char **filenames);
8080

81-
/*
82-
* is_absolute_path
83-
*
84-
* By making this a macro we avoid needing to include path.c in libpq.
85-
*/
86-
#ifndef WIN32
87-
#define IS_DIR_SEP(ch) ((ch) == '/')
88-
89-
#define is_absolute_path(filename) \
81+
#define IS_NONWINDOWS_DIR_SEP(ch) ((ch) == '/')
82+
#define is_nonwindows_absolute_path(filename) \
9083
( \
91-
IS_DIR_SEP((filename)[0]) \
84+
IS_NONWINDOWS_DIR_SEP((filename)[0]) \
9285
)
93-
#else
94-
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
9586

87+
#define IS_WINDOWS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
9688
/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
97-
#define is_absolute_path(filename) \
89+
#define is_windows_absolute_path(filename) \
9890
( \
99-
IS_DIR_SEP((filename)[0]) || \
91+
IS_WINDOWS_DIR_SEP((filename)[0]) || \
10092
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
101-
IS_DIR_SEP((filename)[2])) \
93+
IS_WINDOWS_DIR_SEP((filename)[2])) \
10294
)
95+
96+
/*
97+
* is_absolute_path and IS_DIR_SEP
98+
*
99+
* By using macros here we avoid needing to include path.c in libpq.
100+
*/
101+
#ifndef WIN32
102+
#define IS_DIR_SEP(ch) IS_NONWINDOWS_DIR_SEP(ch)
103+
#define is_absolute_path(filename) is_nonwindows_absolute_path(filename)
104+
#else
105+
#define IS_DIR_SEP(ch) IS_WINDOWS_DIR_SEP(ch)
106+
#define is_absolute_path(filename) is_windows_absolute_path(filename)
103107
#endif
104108

105109
/*

0 commit comments

Comments
 (0)