Skip to content

Commit d10ddf4

Browse files
committed
Use correct path separator for Windows builtin commands.
pg_upgrade produces a platform-specific script to remove the old directory, but on Windows it has not been making sure that the paths it writes as arguments for rmdir and del use the backslash path separator, which will cause these scripts to fail. The fix is backpatched to Release 9.0.
1 parent 9739518 commit d10ddf4

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

contrib/pg_upgrade/check.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ static void check_for_reg_data_type_usage(ClusterInfo *cluster);
2222
static void get_bin_version(ClusterInfo *cluster);
2323

2424

25+
/*
26+
* fix_path_separator
27+
* For non-Windows, just return the argument.
28+
* For Windows convert any forward slash to a backslash
29+
* such as is suitable for arguments to builtin commands
30+
* like RMDIR and DEL.
31+
*/
32+
static char *fix_path_separator(char *path)
33+
{
34+
#ifdef WIN32
35+
36+
char *result;
37+
char *c;
38+
39+
result = pg_strdup(path);
40+
41+
for (c = result; *c != '\0'; c++)
42+
if (*c == '/')
43+
*c = '\\';
44+
45+
return result;
46+
47+
#else
48+
49+
return path;
50+
51+
#endif
52+
}
53+
2554
void
2655
output_check_banner(bool *live_check)
2756
{
@@ -453,7 +482,7 @@ create_script_for_old_cluster_deletion(
453482
#endif
454483

455484
/* delete old cluster's default tablespace */
456-
fprintf(script, RMDIR_CMD " %s\n", old_cluster.pgdata);
485+
fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(old_cluster.pgdata));
457486

458487
/* delete old cluster's alternate tablespaces */
459488
for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
@@ -470,14 +499,17 @@ create_script_for_old_cluster_deletion(
470499
fprintf(script, "\n");
471500
/* remove PG_VERSION? */
472501
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
473-
fprintf(script, RM_CMD " %s%s/PG_VERSION\n",
474-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
502+
fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
503+
fix_path_separator(os_info.tablespaces[tblnum]),
504+
fix_path_separator(old_cluster.tablespace_suffix),
505+
PATH_SEPARATOR);
475506

476507
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
477508
{
478-
fprintf(script, RMDIR_CMD " %s%s/%d\n",
479-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix,
480-
old_cluster.dbarr.dbs[dbnum].db_oid);
509+
fprintf(script, RMDIR_CMD " %s%s%c%d\n",
510+
fix_path_separator(os_info.tablespaces[tblnum]),
511+
fix_path_separator(old_cluster.tablespace_suffix),
512+
PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
481513
}
482514
}
483515
else
@@ -487,7 +519,8 @@ create_script_for_old_cluster_deletion(
487519
* or a version-specific subdirectory.
488520
*/
489521
fprintf(script, RMDIR_CMD " %s%s\n",
490-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
522+
fix_path_separator(os_info.tablespaces[tblnum]),
523+
fix_path_separator(old_cluster.tablespace_suffix));
491524
}
492525

493526
fclose(script);

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define pg_copy_file copy_file
3939
#define pg_mv_file rename
4040
#define pg_link_file link
41+
#define PATH_SEPARATOR '/'
4142
#define RM_CMD "rm -f"
4243
#define RMDIR_CMD "rm -rf"
4344
#define SCRIPT_EXT "sh"
@@ -46,6 +47,7 @@
4647
#define pg_mv_file pgrename
4748
#define pg_link_file win32_pghardlink
4849
#define sleep(x) Sleep(x * 1000)
50+
#define PATH_SEPARATOR '\\'
4951
#define RM_CMD "DEL /q"
5052
#define RMDIR_CMD "RMDIR /s/q"
5153
#define SCRIPT_EXT "bat"

0 commit comments

Comments
 (0)