Skip to content

Commit e4c3c99

Browse files
committed
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.
1 parent ef153ec commit e4c3c99

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contrib/pg_upgrade/option.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,26 @@ parseCommandLine(int argc, char *argv[])
229229
"PGDATAOLD", "-d", "old cluster data resides");
230230
check_required_directory(&new_cluster.pgdata, &new_cluster.pgconfig,
231231
"PGDATANEW", "-D", "new cluster data resides");
232+
233+
#ifndef WIN32
234+
/*
235+
* On Windows, initdb --sync-only will fail with a "Permission denied"
236+
* error on file pg_upgrade_utility.log if pg_upgrade is run inside
237+
* the new cluster directory, so we do a check here.
238+
*/
239+
{
240+
char cwd[MAXPGPATH], new_cluster_pgdata[MAXPGPATH];
241+
242+
strlcpy(new_cluster_pgdata, new_cluster.pgdata, MAXPGPATH);
243+
canonicalize_path(new_cluster_pgdata);
244+
245+
if (!getcwd(cwd, MAXPGPATH))
246+
pg_fatal("cannot find current directory\n");
247+
canonicalize_path(cwd);
248+
if (path_is_prefix_of_path(new_cluster_pgdata, cwd))
249+
pg_fatal("cannot run pg_upgrade from inside the new cluster data directory on Windows\n");
250+
}
251+
#endif
232252
}
233253

234254

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy