aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-08-15 12:03:49 -0400
committerBruce Momjian <bruce@momjian.us>2014-08-15 12:04:03 -0400
commite4c3c99ac3d4777458ef3e94b037438b244b72b6 (patch)
tree52de71544ada987d7872d3a4e18945605eb6e9e6
parentef153ecc55a8f945d576a1e69a51b91046f24bb1 (diff)
downloadpostgresql-e4c3c99ac3d4777458ef3e94b037438b244b72b6.tar.gz
postgresql-e4c3c99ac3d4777458ef3e94b037438b244b72b6.zip
pg_upgrade: error if run from top of new PGDATA on Windows
Print a clear error message in this case, rather than wait for initdb --sync-only to generate a "Permission denied" error.
-rw-r--r--contrib/pg_upgrade/option.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/pg_upgrade/option.c b/contrib/pg_upgrade/option.c
index e0a3c6d7114..2e7c3479d68 100644
--- a/contrib/pg_upgrade/option.c
+++ b/contrib/pg_upgrade/option.c
@@ -229,6 +229,26 @@ parseCommandLine(int argc, char *argv[])
"PGDATAOLD", "-d", "old cluster data resides");
check_required_directory(&new_cluster.pgdata, &new_cluster.pgconfig,
"PGDATANEW", "-D", "new cluster data resides");
+
+#ifndef WIN32
+ /*
+ * On Windows, initdb --sync-only will fail with a "Permission denied"
+ * error on file pg_upgrade_utility.log if pg_upgrade is run inside
+ * the new cluster directory, so we do a check here.
+ */
+ {
+ char cwd[MAXPGPATH], new_cluster_pgdata[MAXPGPATH];
+
+ strlcpy(new_cluster_pgdata, new_cluster.pgdata, MAXPGPATH);
+ canonicalize_path(new_cluster_pgdata);
+
+ if (!getcwd(cwd, MAXPGPATH))
+ pg_fatal("cannot find current directory\n");
+ canonicalize_path(cwd);
+ if (path_is_prefix_of_path(new_cluster_pgdata, cwd))
+ pg_fatal("cannot run pg_upgrade from inside the new cluster data directory on Windows\n");
+ }
+#endif
}