Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Use correct path separator for Windows builtin commands.
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 3 Sep 2012 22:14:06 +0000 (18:14 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 3 Sep 2012 22:14:06 +0000 (18:14 -0400)
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.

contrib/pg_upgrade/check.c
contrib/pg_upgrade/pg_upgrade.h

index d5d6bedb68ef7b8ec11e019569c92f37ad9388ee..453b007899692382aa61b7ce203cad815d1d604d 100644 (file)
@@ -19,6 +19,35 @@ static void check_for_isn_and_int8_passing_mismatch(migratorContext *ctx,
 static void check_for_reg_data_type_usage(migratorContext *ctx, Cluster whichCluster);
 
 
+/*
+ * 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(migratorContext *ctx, bool *live_check)
 {
@@ -402,7 +431,7 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
 #endif
 
    /* delete old cluster's default tablespace */
-   fprintf(script, RMDIR_CMD " %s\n", ctx->old.pgdata);
+   fprintf(script, RMDIR_CMD " %s\n", fix_path_separator(ctx->old.pgdata));
 
    /* delete old cluster's alternate tablespaces */
    for (tblnum = 0; tblnum < ctx->num_tablespaces; tblnum++)
@@ -419,14 +448,17 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
            fprintf(script, "\n");
            /* remove PG_VERSION? */
            if (GET_MAJOR_VERSION(ctx->old.major_version) <= 804)
-               fprintf(script, RM_CMD " %s%s/PG_VERSION\n",
-                       ctx->tablespaces[tblnum], ctx->old.tablespace_suffix);
+               fprintf(script, RM_CMD " %s%s%cPG_VERSION\n",
+                       fix_path_separator(ctx->tablespaces[tblnum]),
+                       fix_path_separator(ctx->old.tablespace_suffix),
+                       PATH_SEPARATOR);
 
            for (dbnum = 0; dbnum < ctx->new.dbarr.ndbs; dbnum++)
            {
-               fprintf(script, RMDIR_CMD " %s%s/%d\n",
-                       ctx->tablespaces[tblnum], ctx->old.tablespace_suffix,
-                       ctx->old.dbarr.dbs[dbnum].db_oid);
+               fprintf(script, RMDIR_CMD " %s%s%c%d\n",
+                       fix_path_separator(ctx->tablespaces[tblnum]),
+                       fix_path_separator(ctx->old.tablespace_suffix),
+                       PATH_SEPARATOR, ctx->old.dbarr.dbs[dbnum].db_oid);
            }
        }
        else
@@ -436,7 +468,8 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
             * or a version-specific subdirectory.
             */
            fprintf(script, RMDIR_CMD " %s%s\n",
-                   ctx->tablespaces[tblnum], ctx->old.tablespace_suffix);
+                   fix_path_separator(ctx->tablespaces[tblnum]),
+                   fix_path_separator(ctx->old.tablespace_suffix));
    }
 
    fclose(script);
index bfcabb390e0bcd8df0441d28052dd5175332f9e6..3c3ca6daf6a5472f58a781a3012e7173a4370cd6 100644 (file)
@@ -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 SHELL_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 SHELL_EXT          "bat"