From 6638c9aaf881b156fafc05371e8ed21f0cdda66e Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 24 Nov 2015 17:18:27 -0500 Subject: [PATCH] pg_upgrade: fix CopyFile() on Windows to fail on file existence Also fix getErrorText() to return the right error string on failure. This behavior now matches that of other operating systems. Report by Noah Misch Backpatch through 9.1 --- contrib/pg_upgrade/file.c | 2 +- contrib/pg_upgrade/util.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c index 36dee3eae7b..4f0f1ae4a8f 100644 --- a/contrib/pg_upgrade/file.c +++ b/contrib/pg_upgrade/file.c @@ -37,7 +37,7 @@ copyAndUpdateFile(pageCnvCtx *pageConverter, #ifndef WIN32 if (copy_file(src, dst, force) == -1) #else - if (CopyFile(src, dst, force) == 0) + if (CopyFile(src, dst, !force) == 0) #endif return getErrorText(errno); else diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c index de948c3eca6..1e5f3652cad 100644 --- a/contrib/pg_upgrade/util.c +++ b/contrib/pg_upgrade/util.c @@ -226,6 +226,8 @@ getErrorText(int errNum) { #ifdef WIN32 _dosmaperr(GetLastError()); + /* _dosmaperr sets errno, so we copy errno here */ + errNum = errno; #endif return pg_strdup(strerror(errNum)); } -- 2.39.5