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

Commit 504aeea

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 2a2352e commit 504aeea

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
@@ -23,6 +23,35 @@ static void check_for_reg_data_type_usage(ClusterInfo *cluster);
2323
static void get_bin_version(ClusterInfo *cluster);
2424

2525

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

546575
/* delete old cluster's default tablespace */
547-
fprintf(script, RMDIR_CMD " %s\n", old_cluster.pgdata);
576+
fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(old_cluster.pgdata));
548577

549578
/* delete old cluster's alternate tablespaces */
550579
for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
@@ -561,14 +590,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
561590
fprintf(script, "\n");
562591
/* remove PG_VERSION? */
563592
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
564-
fprintf(script, RM_CMD " %s%s/PG_VERSION\n",
565-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
593+
fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
594+
fix_path_separator(os_info.tablespaces[tblnum]),
595+
fix_path_separator(old_cluster.tablespace_suffix),
596+
PATH_SEPARATOR);
566597

567598
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
568599
{
569-
fprintf(script, RMDIR_CMD " %s%s/%d\n",
570-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix,
571-
old_cluster.dbarr.dbs[dbnum].db_oid);
600+
fprintf(script, RMDIR_CMD " %s%s%c%d\n",
601+
fix_path_separator(os_info.tablespaces[tblnum]),
602+
fix_path_separator(old_cluster.tablespace_suffix),
603+
PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
572604
}
573605
}
574606
else
@@ -578,7 +610,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
578610
* or a version-specific subdirectory.
579611
*/
580612
fprintf(script, RMDIR_CMD " %s%s\n",
581-
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
613+
fix_path_separator(os_info.tablespaces[tblnum]),
614+
fix_path_separator(old_cluster.tablespace_suffix));
582615
}
583616

584617
fclose(script);

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern char *output_files[];
7272
#define pg_copy_file copy_file
7373
#define pg_mv_file rename
7474
#define pg_link_file link
75+
#define PATH_SEPARATOR '/'
7576
#define RM_CMD "rm -f"
7677
#define RMDIR_CMD "rm -rf"
7778
#define SCRIPT_EXT "sh"
@@ -81,6 +82,7 @@ extern char *output_files[];
8182
#define pg_mv_file pgrename
8283
#define pg_link_file win32_pghardlink
8384
#define sleep(x) Sleep(x * 1000)
85+
#define PATH_SEPARATOR '\\'
8486
#define RM_CMD "DEL /q"
8587
#define RMDIR_CMD "RMDIR /s/q"
8688
#define SCRIPT_EXT "bat"

0 commit comments

Comments
 (0)