1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-02 11:44:50 +03:00

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.
This commit is contained in:
Andrew Dunstan 2012-09-03 18:11:02 -04:00
parent c879e82b37
commit f88ad86fba
2 changed files with 42 additions and 7 deletions

View File

@ -23,6 +23,35 @@ static void check_for_reg_data_type_usage(ClusterInfo *cluster);
static void get_bin_version(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 void
output_check_banner(bool *live_check) output_check_banner(bool *live_check)
{ {
@ -544,7 +573,7 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
#endif #endif
/* delete old cluster's default tablespace */ /* 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 */ /* delete old cluster's alternate tablespaces */
for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++) for (tblnum = 0; tblnum < os_info.num_tablespaces; tblnum++)
@ -561,14 +590,17 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
fprintf(script, "\n"); fprintf(script, "\n");
/* remove PG_VERSION? */ /* remove PG_VERSION? */
if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804) if (GET_MAJOR_VERSION(old_cluster.major_version) <= 804)
fprintf(script, RM_CMD " %s%s/PG_VERSION\n", fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix); fix_path_separator(os_info.tablespaces[tblnum]),
fix_path_separator(old_cluster.tablespace_suffix),
PATH_SEPARATOR);
for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++)
{ {
fprintf(script, RMDIR_CMD " %s%s/%d\n", fprintf(script, RMDIR_CMD " %s%s%c%d\n",
os_info.tablespaces[tblnum], old_cluster.tablespace_suffix, fix_path_separator(os_info.tablespaces[tblnum]),
old_cluster.dbarr.dbs[dbnum].db_oid); fix_path_separator(old_cluster.tablespace_suffix),
PATH_SEPARATOR, old_cluster.dbarr.dbs[dbnum].db_oid);
} }
} }
else else
@ -578,7 +610,8 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
* or a version-specific subdirectory. * or a version-specific subdirectory.
*/ */
fprintf(script, RMDIR_CMD " %s%s\n", 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); fclose(script);

View File

@ -72,6 +72,7 @@ extern char *output_files[];
#define pg_copy_file copy_file #define pg_copy_file copy_file
#define pg_mv_file rename #define pg_mv_file rename
#define pg_link_file link #define pg_link_file link
#define PATH_SEPARATOR '/'
#define RM_CMD "rm -f" #define RM_CMD "rm -f"
#define RMDIR_CMD "rm -rf" #define RMDIR_CMD "rm -rf"
#define SCRIPT_EXT "sh" #define SCRIPT_EXT "sh"
@ -81,6 +82,7 @@ extern char *output_files[];
#define pg_mv_file pgrename #define pg_mv_file pgrename
#define pg_link_file win32_pghardlink #define pg_link_file win32_pghardlink
#define sleep(x) Sleep(x * 1000) #define sleep(x) Sleep(x * 1000)
#define PATH_SEPARATOR '\\'
#define RM_CMD "DEL /q" #define RM_CMD "DEL /q"
#define RMDIR_CMD "RMDIR /s/q" #define RMDIR_CMD "RMDIR /s/q"
#define SCRIPT_EXT "bat" #define SCRIPT_EXT "bat"