pg_upgrade: fix CopyFile() on Windows to fail on file existence
authorBruce Momjian <[email protected]>
Tue, 24 Nov 2015 22:18:27 +0000 (17:18 -0500)
committerBruce Momjian <[email protected]>
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 40463c61369e163762e0291185b36b4a358d7593..a1b0176590ab8ff39192c301d5ec543847d2db84 100644 (file)
@@ -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
index c0d9deebca4bf609050b7794a436aa3a7e89df63..d323045deb399d9f755d34fb6aeeb3b5322ee554 100644 (file)
@@ -253,6 +253,8 @@ getErrorText(int errNum)
 {
 #ifdef WIN32
    _dosmaperr(GetLastError());
+   /* _dosmaperr sets errno, so we copy errno here */
+   errNum = errno;
 #endif
    return pg_strdup(strerror(errNum));
 }