summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro2022-10-25 02:10:49 +0000
committerThomas Munro2022-10-25 02:10:49 +0000
commit359d601095ce2361bad50f9f8b0bcfe4da1eb886 (patch)
tree87b7583cc16bfc3096b0718996395ae10bf37157
parentf186c7c88522c2c25b31566b4a5e00749ca7820c (diff)
Fix symlink() errno on Windows.
Ancient bug noticed while working on a test suite for these functions. https://postgr.es/m/CA%2BhUKG%2BajSQ_8eu2AogTncOnZ5me2D-Cn66iN_-wZnRjLN%2Bicg%40mail.gmail.com
-rw-r--r--src/port/dirmod.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index ae6301dd6c..51c9bded8f 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -197,7 +197,10 @@ pgsymlink(const char *oldpath, const char *newpath)
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, 0);
if (dirhandle == INVALID_HANDLE_VALUE)
+ {
+ _dosmaperr(GetLastError());
return -1;
+ }
/* make sure we have an unparsed native win32 path */
if (memcmp("\\??\\", oldpath, 4) != 0)
@@ -230,8 +233,11 @@ pgsymlink(const char *oldpath, const char *newpath)
0, 0, &len, 0))
{
LPSTR msg;
+ int save_errno;
+
+ _dosmaperr(GetLastError());
+ save_errno = errno;
- errno = 0;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_SYSTEM,
@@ -251,6 +257,9 @@ pgsymlink(const char *oldpath, const char *newpath)
CloseHandle(dirhandle);
RemoveDirectory(newpath);
+
+ errno = save_errno;
+
return -1;
}