Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba58266

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 61838d2 commit ba58266

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/bin/pg_basebackup/pg_basebackup.c

+15-5
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,22 @@ tablespace_list_append(const char *arg)
276276
}
277277

278278
/*
279-
* This check isn't absolutely necessary. But all tablespaces are created
280-
* with absolute directories, so specifying a non-absolute path here would
281-
* just never match, possibly confusing users. It's also good to be
282-
* consistent with the new_dir check.
279+
* All tablespaces are created with absolute directories, so specifying a
280+
* non-absolute path here would just never match, possibly confusing users.
281+
* Since we don't know whether the remote side is Windows or not, and it
282+
* might be different than the local side, permit any path that could be
283+
* absolute under either set of rules.
284+
*
285+
* (There is little practical risk of confusion here, because someone
286+
* running entirely on Linux isn't likely to have a relative path that
287+
* begins with a backslash or something that looks like a drive
288+
* specification. If they do, and they also incorrectly believe that
289+
* a relative path is acceptable here, we'll silently fail to warn them
290+
* of their mistake, and the -T option will just not get applied, same
291+
* as if they'd specified -T for a nonexistent tablespace.)
283292
*/
284-
if (!is_absolute_path(cell->old_dir))
293+
if (!is_nonwindows_absolute_path(cell->old_dir) &&
294+
!is_windows_absolute_path(cell->old_dir))
285295
{
286296
fprintf(stderr, _("%s: old directory is not an absolute path in tablespace mapping: %s\n"),
287297
progname, cell->old_dir);

src/include/port.h

+19-15
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,32 @@ extern void get_parent_directory(char *path);
6666
extern char **pgfnames(const char *path);
6767
extern void pgfnames_cleanup(char **filenames);
6868

69-
/*
70-
* is_absolute_path
71-
*
72-
* By making this a macro we avoid needing to include path.c in libpq.
73-
*/
74-
#ifndef WIN32
75-
#define IS_DIR_SEP(ch) ((ch) == '/')
76-
77-
#define is_absolute_path(filename) \
69+
#define IS_NONWINDOWS_DIR_SEP(ch) ((ch) == '/')
70+
#define is_nonwindows_absolute_path(filename) \
7871
( \
79-
IS_DIR_SEP((filename)[0]) \
72+
IS_NONWINDOWS_DIR_SEP((filename)[0]) \
8073
)
81-
#else
82-
#define IS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
8374

75+
#define IS_WINDOWS_DIR_SEP(ch) ((ch) == '/' || (ch) == '\\')
8476
/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
85-
#define is_absolute_path(filename) \
77+
#define is_windows_absolute_path(filename) \
8678
( \
87-
IS_DIR_SEP((filename)[0]) || \
79+
IS_WINDOWS_DIR_SEP((filename)[0]) || \
8880
(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
89-
IS_DIR_SEP((filename)[2])) \
81+
IS_WINDOWS_DIR_SEP((filename)[2])) \
9082
)
83+
84+
/*
85+
* is_absolute_path and IS_DIR_SEP
86+
*
87+
* By using macros here we avoid needing to include path.c in libpq.
88+
*/
89+
#ifndef WIN32
90+
#define IS_DIR_SEP(ch) IS_NONWINDOWS_DIR_SEP(ch)
91+
#define is_absolute_path(filename) is_nonwindows_absolute_path(filename)
92+
#else
93+
#define IS_DIR_SEP(ch) IS_WINDOWS_DIR_SEP(ch)
94+
#define is_absolute_path(filename) is_windows_absolute_path(filename)
9195
#endif
9296

9397
/* Portable locale initialization (in exec.c) */

0 commit comments

Comments
 (0)