]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Have pg_upgrade create its output files in the current directory, rather
authorBruce Momjian <bruce@momjian.us>
Sat, 12 Jun 2010 17:05:29 +0000 (17:05 +0000)
committerBruce Momjian <bruce@momjian.us>
Sat, 12 Jun 2010 17:05:29 +0000 (17:05 +0000)
than in a subdirectory of the $HOME directory, or $TMP in Windows.

contrib/pg_upgrade/check.c
contrib/pg_upgrade/dump.c
contrib/pg_upgrade/function.c
contrib/pg_upgrade/option.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/version.c
contrib/pg_upgrade/version_old_8_3.c

index f989229f86a905d6b18b386a12d0b0c6948e4e56..b6c7d3101d37aca78667d69dcbde3bee30aca7df 100644 (file)
@@ -381,7 +381,7 @@ create_script_for_old_cluster_deletion(migratorContext *ctx,
        prep_status(ctx, "Creating script to delete old cluster");
 
        snprintf(*deletion_script_file_name, MAXPGPATH, "%s/delete_old_cluster.%s",
-                        ctx->output_dir, EXEC_EXT);
+                        ctx->cwd, EXEC_EXT);
 
        if ((script = fopen(*deletion_script_file_name, "w")) == NULL)
                pg_log(ctx, PG_FATAL, "Could not create necessary file:  %s\n",
index f0f827aeb5b156a06445e7c4783a85ee08f6c08d..f3060d54d1b2c7f7fb190752d1fb8e0cfa859cc2 100644 (file)
@@ -21,7 +21,7 @@ generate_old_dump(migratorContext *ctx)
        exec_prog(ctx, true,
                          SYSTEMQUOTE "\"%s/pg_dumpall\" --port %d --schema-only "
                          "--binary-upgrade > \"%s/" ALL_DUMP_FILE "\"" SYSTEMQUOTE,
-                         ctx->new.bindir, ctx->old.port, ctx->output_dir);
+                         ctx->new.bindir, ctx->old.port, ctx->cwd);
        check_ok(ctx);
 }
 
@@ -52,13 +52,13 @@ split_old_dump(migratorContext *ctx)
        char            filename[MAXPGPATH];
        bool            suppressed_username = false;
 
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, ALL_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, ALL_DUMP_FILE);
        if ((all_dump = fopen(filename, "r")) == NULL)
                pg_log(ctx, PG_FATAL, "Cannot open dump file %s\n", filename);
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, GLOBALS_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, GLOBALS_DUMP_FILE);
        if ((globals_dump = fopen(filename, "w")) == NULL)
                pg_log(ctx, PG_FATAL, "Cannot write to dump file %s\n", filename);
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, DB_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, DB_DUMP_FILE);
        if ((db_dump = fopen(filename, "w")) == NULL)
                pg_log(ctx, PG_FATAL, "Cannot write to dump file %s\n", filename);
        current_output = globals_dump;
index dfe85ddf7df4323e582984df95030ee6ac16cf44..d9b54b81fe27aa97f2c88e54d4185bbdba4217ec 100644 (file)
@@ -213,7 +213,7 @@ check_loadable_libraries(migratorContext *ctx)
        prep_status(ctx, "Checking for presence of required libraries");
 
        snprintf(output_path, sizeof(output_path), "%s/loadable_libraries.txt",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (libnum = 0; libnum < ctx->num_libraries; libnum++)
        {
index df737ac228dcbc21adca66f006827b3d9bcff2ee..83300a9e51e90c59b596823e67f7c6f0ef283513 100644 (file)
@@ -84,20 +84,7 @@ parseCommandLine(migratorContext *ctx, int argc, char *argv[])
        if (user_id == 0)
                pg_log(ctx, PG_FATAL, "%s: cannot be run as root\n", ctx->progname);
 
-#ifndef WIN32
-       get_home_path(ctx->home_dir);
-#else
-       {
-               char       *tmppath;
-
-               /* TMP is the best place on Windows, rather than APPDATA */
-               if ((tmppath = getenv("TMP")) == NULL)
-                       pg_log(ctx, PG_FATAL, "TMP environment variable is not set.\n");
-               snprintf(ctx->home_dir, MAXPGPATH, "%s", tmppath);
-       }
-#endif
-
-       snprintf(ctx->output_dir, MAXPGPATH, "%s/" OUTPUT_SUBDIR, ctx->home_dir);
+       getcwd(ctx->cwd, MAXPGPATH);
 
        while ((option = getopt_long(argc, argv, "d:D:b:B:cgG:kl:p:P:u:v",
                                                                 long_options, &optindex)) != -1)
index 7d7abe6c23cb11ca78647f5dd4020abfa2ea30dc..b314a1f1c39892d457c8974f300ad6eed2df9118 100644 (file)
@@ -18,7 +18,6 @@ static void copy_clog_xlog_xid(migratorContext *ctx);
 static void set_frozenxids(migratorContext *ctx);
 static void setup(migratorContext *ctx, char *argv0, bool live_check);
 static void cleanup(migratorContext *ctx);
-static void create_empty_output_directory(migratorContext *ctx);
 
 
 int
@@ -37,8 +36,6 @@ main(int argc, char **argv)
 
        setup(&ctx, argv[0], live_check);
 
-       create_empty_output_directory(&ctx);
-
        check_cluster_versions(&ctx);
        check_cluster_compatibility(&ctx, live_check);
 
@@ -201,7 +198,7 @@ prepare_new_databases(migratorContext *ctx)
        exec_prog(ctx, true,
                          SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on --port %d "
                          "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
-                         ctx->new.bindir, ctx->new.port, ctx->output_dir,
+                         ctx->new.bindir, ctx->new.port, ctx->cwd,
                          GLOBALS_DUMP_FILE, ctx->logfile);
        check_ok(ctx);
 
@@ -223,7 +220,7 @@ create_new_objects(migratorContext *ctx)
        exec_prog(ctx, true,
                          SYSTEMQUOTE "\"%s/psql\" --set ON_ERROR_STOP=on --port %d "
                          "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
-                         ctx->new.bindir, ctx->new.port, ctx->output_dir,
+                         ctx->new.bindir, ctx->new.port, ctx->cwd,
                          DB_DUMP_FILE, ctx->logfile);
        check_ok(ctx);
 
@@ -399,33 +396,10 @@ cleanup(migratorContext *ctx)
        if (ctx->debug_fd)
                fclose(ctx->debug_fd);
 
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, ALL_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, ALL_DUMP_FILE);
        unlink(filename);
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, GLOBALS_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, GLOBALS_DUMP_FILE);
        unlink(filename);
-       snprintf(filename, sizeof(filename), "%s/%s", ctx->output_dir, DB_DUMP_FILE);
+       snprintf(filename, sizeof(filename), "%s/%s", ctx->cwd, DB_DUMP_FILE);
        unlink(filename);
 }
-
-
-/*
- * create_empty_output_directory
- *
- *     Create empty directory for output files
- */
-static void
-create_empty_output_directory(migratorContext *ctx)
-{
-       /*
-        *      rmtree() outputs a warning if the directory does not exist,
-        *      so we try to create the directory first.
-        */
-       if (mkdir(ctx->output_dir, S_IRWXU) != 0)
-       {
-               if (errno == EEXIST)
-                       rmtree(ctx->output_dir, false);
-               else
-                       pg_log(ctx, PG_FATAL, "Cannot create subdirectory %s: %s\n",
-                          ctx->output_dir, getErrorText(errno));
-       }
-}
index e6f4d3ea11ab80bc399db97a597ea942b05b6e7d..c893111ec3fd08bdb9d68495b39caf9dbd43f0fe 100644 (file)
@@ -29,8 +29,6 @@
 #define OVERWRITE_MESSAGE      "  %-" MESSAGE_WIDTH "." MESSAGE_WIDTH "s\r"
 #define GET_MAJOR_VERSION(v)   ((v) / 100)
 
-#define OUTPUT_SUBDIR          "pg_upgrade_output"
-
 #define ALL_DUMP_FILE          "pg_upgrade_dump_all.sql"
 /* contains both global db information and CREATE DATABASE commands */
 #define GLOBALS_DUMP_FILE      "pg_upgrade_dump_globals.sql"
@@ -217,8 +215,7 @@ typedef struct
        const char *progname;           /* complete pathname for this program */
        char       *exec_path;          /* full path to my executable */
        char       *user;                       /* username for clusters */
-       char            home_dir[MAXPGPATH];    /* name of user's home directory */
-       char            output_dir[MAXPGPATH];  /* directory for pg_upgrade output */
+       char            cwd[MAXPGPATH]; /* directory for pg_upgrade output */
        char      **tablespaces;        /* tablespaces */
        int                     num_tablespaces;
        char      **libraries;          /* loadable libraries */
index 72a4031d72bdf86aec2110924bfaba415d8e62ed..e14fdf14ed3a0f9769b9207fe7f9f1ee969d818c 100644 (file)
@@ -28,7 +28,7 @@ new_9_0_populate_pg_largeobject_metadata(migratorContext *ctx, bool check_mode,
        prep_status(ctx, "Checking for large objects");
 
        snprintf(output_path, sizeof(output_path), "%s/pg_largeobject.sql",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
index 8d56893f778e7fda17c73d1ad8ec0d3088aeaf3e..982fcc6abcc4665389babcd2e944940a552d77a9 100644 (file)
@@ -28,7 +28,7 @@ old_8_3_check_for_name_data_type_usage(migratorContext *ctx, Cluster whichCluste
        prep_status(ctx, "Checking for invalid 'name' user columns");
 
        snprintf(output_path, sizeof(output_path), "%s/tables_using_name.txt",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -123,7 +123,7 @@ old_8_3_check_for_tsquery_usage(migratorContext *ctx, Cluster whichCluster)
        prep_status(ctx, "Checking for tsquery user columns");
 
        snprintf(output_path, sizeof(output_path), "%s/tables_using_tsquery.txt",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -222,7 +222,7 @@ old_8_3_check_for_isn_and_int8_passing_mismatch(migratorContext *ctx, Cluster wh
        }
 
        snprintf(output_path, sizeof(output_path), "%s/contrib_isn_and_int8_pass_by_value.txt",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -312,7 +312,7 @@ old_8_3_rebuild_tsvector_tables(migratorContext *ctx, bool check_mode,
        prep_status(ctx, "Checking for tsvector user columns");
 
        snprintf(output_path, sizeof(output_path), "%s/rebuild_tsvector_tables.sql",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -457,7 +457,7 @@ old_8_3_invalidate_hash_gin_indexes(migratorContext *ctx, bool check_mode,
        prep_status(ctx, "Checking for hash and gin indexes");
 
        snprintf(output_path, sizeof(output_path), "%s/reindex_hash_and_gin.sql",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -573,7 +573,7 @@ old_8_3_invalidate_bpchar_pattern_ops_indexes(migratorContext *ctx, bool check_m
        prep_status(ctx, "Checking for bpchar_pattern_ops indexes");
 
        snprintf(output_path, sizeof(output_path), "%s/reindex_bpchar_ops.sql",
-                        ctx->output_dir);
+                        ctx->cwd);
 
        for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
        {
@@ -705,7 +705,7 @@ old_8_3_create_sequence_script(migratorContext *ctx, Cluster whichCluster)
        bool            found = false;
        char       *output_path = pg_malloc(ctx, MAXPGPATH);
 
-       snprintf(output_path, MAXPGPATH, "%s/adjust_sequences.sql", ctx->output_dir);
+       snprintf(output_path, MAXPGPATH, "%s/adjust_sequences.sql", ctx->cwd);
 
        prep_status(ctx, "Creating script to adjust sequences");