pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Dmitry Koval <d.koval@postgrespro.ru>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
Date: Wed, 17 Nov 2021 13:29:02 +0300
Message-ID: <b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru> (raw )
In-Reply-To: <17288-6b58a91025a8a8a3@postgresql.org >
References: <17288-6b58a91025a8a8a3@postgresql.org >
Attachments: patch + screenshot with error.
Attachments:
0001-Fixed-Windows-stat-emulation-working-with-streams.patch (text/plain, 2.0K) download
From 407184db12af0a7689e73824ade6f2d2cbeaaa0c Mon Sep 17 00:00:00 2001
From: Koval Dmitry <d.koval@postgrespro.ru>
Date: Wed, 17 Nov 2021 13:23:50 +0300
Subject: [PATCH] Fixed Windows stat() emulation: working with streams
---
src/port/win32stat.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/port/win32stat.c b/src/port/win32stat.c
index 2ad8ee1359..230bd093ed 100644
--- a/src/port/win32stat.c
+++ b/src/port/win32stat.c
@@ -112,7 +112,7 @@ fileattr_to_unixmode(int attr)
* Convert WIN32 file information (from a HANDLE) to a struct stat.
*/
static int
-fileinfo_to_stat(HANDLE hFile, struct stat *buf)
+fileinfo_to_stat(HANDLE hFile, int fileno, const char *name, struct stat *buf)
{
BY_HANDLE_FILE_INFORMATION fiData;
@@ -124,7 +124,25 @@ fileinfo_to_stat(HANDLE hFile, struct stat *buf)
*/
if (!GetFileInformationByHandle(hFile, &fiData))
{
- _dosmaperr(GetLastError());
+ DWORD error = GetLastError();
+
+ switch (error)
+ {
+ case ERROR_INVALID_PARAMETER:
+ case ERROR_INVALID_FUNCTION:
+ case ERROR_NOT_SUPPORTED:
+
+ /*
+ * Object is other than real file (stdout, for example). So
+ * need to call _fstat64 in this case. "struct stat" should
+ * match "struct __stat64", see "struct stat" definition.
+ */
+ if (fileno >= 0)
+ return _fstat64(fileno, (struct __stat64 *) buf);
+ else if (name)
+ return _stat64(name, (struct __stat64 *) buf);
+ }
+ _dosmaperr(error);
return -1;
}
@@ -276,7 +294,7 @@ _pgstat64(const char *name, struct stat *buf)
}
/* At last we can invoke fileinfo_to_stat */
- ret = fileinfo_to_stat(hFile, buf);
+ ret = fileinfo_to_stat(hFile, -1, name, buf);
CloseHandle(hFile);
return ret;
@@ -301,7 +319,7 @@ _pgfstat64(int fileno, struct stat *buf)
* ERROR_DELETE_PENDING.
*/
- return fileinfo_to_stat(hFile, buf);
+ return fileinfo_to_stat(hFile, fileno, NULL, buf);
}
#endif /* WIN32 */
--
2.31.0.windows.1
01.png (image/png, 27.0K) download
view image
view thread (29+ messages) latest in thread
Message-ID: <b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru>
Permalink: ../b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru/
Also on: postgresql.org/message-id/b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: d.koval@postgrespro.ru, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
In-Reply-To: <b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox