aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2012-09-03 18:11:17 -0400
committerAndrew Dunstan <andrew@dunslane.net>2012-09-03 18:11:17 -0400
commitd10ddf4d510a5e366775f9a6bb20d0104ff1bcfd (patch)
tree290a62fc03aa9b00764c33f743e3eb864ccf4e00
parent97395185b85b786523ee41225b53bd84c98d34f4 (diff)
downloadpostgresql-d10ddf4d510a5e366775f9a6bb20d0104ff1bcfd.tar.gz
postgresql-d10ddf4d510a5e366775f9a6bb20d0104ff1bcfd.zip
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.
-rw-r--r--contrib/pg_upgrade/check.c47
-rw-r--r--contrib/pg_upgrade/pg_upgrade.h2
2 files changed, 42 insertions, 7 deletions
diff --git a/contrib/pg_upgrade/check.c b/contrib/pg_upgrade/check.c
index 6a3a5f39d95..5699c66019f 100644
--- a/contrib/pg_upgrade/check.c
+++ b/contrib/pg_upgrade/check.c
@@ -22,6 +22,35 @@ static void check_for_reg_data_type_usage(ClusterInfo *cluster);
static void get_bin_version(ClusterInfo *cluster);
+/*
+ * fix_path_separator
+ * For non-Windows, just return the argument.
+ * For Windows convert any forward slash to a backslash
+ * such as is suitable for arguments to builtin commands
+ * like RMDIR and DEL.
+ */
+static char *fix_path_separator(char *path)
+{
+#ifdef WIN32
+
+ char *result;
+ char *c;
+
+ result = pg_strdup(path);
+
+ for (c = result; *c != '\0'; c++)
+ if (*c == '/')
+ *c = '\\';
+
+ return result;
+
+#else
+
+ return path;
+
+#endif
+}
+
void
output_check_banner(bool *live_check)
{
@@ -453,7 +482,7 @@ create_script_for_old_cluster_deletion(
#endif
/* delete old cluster's default tablespace */
- fprintf(script, RMDIR_CMD " %s\n", old_cluster.pgdata);
+ fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(old_cluster.pgdata));
/* delete old cluster's alternate tablespaces */
for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
@@ -470,14 +499,17 @@ create_script_for_old_cluster_deletion(
fprintf(script, "\n");
/* remove PG_VERSION? */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
- fprintf(script, RM_CMD " %s%s/PG_VERSION\n",
- os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
+ fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
+ fix_path_separator(os_info.tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespace_suffix),
+ PATH_SEPARATOR);
for (dbnum = 0; dbnum < new_cluster.dbarr.ndbs; dbnum++)
{
- fprintf(script, RMDIR_CMD " %s%s/%d\n",
- os_info.tablespaces[tblnum], old_cluster.tablespace_suffix,
- old_cluster.dbarr.dbs[dbnum].db_oid);
+ fprintf(script, RMDIR_CMD " %s%s%c%d\n",
+ fix_path_separator(os_info.tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespace_suffix),
+ PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
}
}
else
@@ -487,7 +519,8 @@ create_script_for_old_cluster_deletion(
* or a version-specific subdirectory.
*/
fprintf(script, RMDIR_CMD " %s%s\n",
- os_info.tablespaces[tblnum], old_cluster.tablespace_suffix);
+ fix_path_separator(os_info.tablespaces[tblnum]),
+ fix_path_separator(old_cluster.tablespace_suffix));
}
fclose(script);
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
index 40f03d666f3..51a04473a64 100644
--- a/contrib/pg_upgrade/pg_upgrade.h
+++ b/contrib/pg_upgrade/pg_upgrade.h
@@ -38,6 +38,7 @@
#define pg_copy_file copy_file
#define pg_mv_file rename
#define pg_link_file link
+#define PATH_SEPARATOR '/'
#define RM_CMD "rm -f"
#define RMDIR_CMD "rm -rf"
#define SCRIPT_EXT "sh"
@@ -46,6 +47,7 @@
#define pg_mv_file pgrename
#define pg_link_file win32_pghardlink
#define sleep(x) Sleep(x * 1000)
+#define PATH_SEPARATOR '\\'
#define RM_CMD "DEL /q"
#define RMDIR_CMD "RMDIR /s/q"
#define SCRIPT_EXT "bat"