]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pg_upgrade: fix CopyFile() on Windows to fail on file existence
authorBruce Momjian <bruce@momjian.us>
Tue, 24 Nov 2015 22:18:27 +0000 (17:18 -0500)
committerBruce Momjian <bruce@momjian.us>
Tue, 24 Nov 2015 22:18:27 +0000 (17:18 -0500)
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
contrib/pg_upgrade/util.c

index 2aa48f049adbec048bd55bd3a4cba3e28459cd52..fc78a06d8fb9fb65ce2e0ea48f59263e803a1302 100644 (file)
@@ -41,7 +41,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
index 27dcd22a9b3e5875c0aeadc1a661f0ddaff44715..c32cfcae645a72ba8aa2ae483fe0224839a75518 100644 (file)
@@ -229,6 +229,8 @@ getErrorText(int errNum)
 {
 #ifdef WIN32
        _dosmaperr(GetLastError());
+       /* _dosmaperr sets errno, so we copy errno here */
+       errNum = errno;
 #endif
        return strdup(strerror(errNum));
 }