Well, this is embarassing. Sorry for the inconvenience. Some part of my company's network infrastruture must have mangled the attachment. Both mails were sent using a combination of git format-patch and git send-email. However, as this is my first foray into this email-based workflow, I won't rule out a failure on my part. Bear with me and let's try again.
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 7f7a0f1ce7..684db4a17a 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -3838,6 +3838,18 @@ bool checkSeek(FILE *fp) { pgoff_t tpos; + struct stat st; + + /* Check if this is a terminal descriptor */ + if (isatty(fileno(fp))) { + return false; + } + + /* Check if this is an unseekable character special device or pipe */ + if ((fstat(fileno(fp), &st) == 0) && (S_ISCHR(st.st_mode) + || S_ISFIFO(st.st_mode))) { + return false; + } /* Check that ftello works on this file */ tpos = ftello(fp); diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h index 296905bc6c..892d0bb401 100644 --- a/src/include/port/win32_port.h +++ b/src/include/port/win32_port.h @@ -329,6 +329,12 @@ extern int _pglstat64(const char *name, struct stat *buf); #ifndef S_ISREG #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif +#ifndef S_ISFIFO +#define S_ISFIFO(m) (((m) & S_IFMT) == _S_IFIFO) +#endif +#ifndef S_ISCHR +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#endif /* * In order for lstat() to be able to report junction points as symlinks, we diff --git a/src/port/win32stat.c b/src/port/win32stat.c index e6553e4030..7ab0983a74 100644 --- a/src/port/win32stat.c +++ b/src/port/win32stat.c @@ -256,35 +256,65 @@ _pgstat64(const char *name, struct stat *buf) int _pgfstat64(int fileno, struct stat *buf) { - HANDLE hFile = (HANDLE) _get_osfhandle(fileno); - BY_HANDLE_FILE_INFORMATION fiData; + HANDLE hFile = (HANDLE) _get_osfhandle(fileno); + DWORD fileType = FILE_TYPE_UNKNOWN; + DWORD lastError; + unsigned short st_mode; - if (hFile == INVALID_HANDLE_VALUE || buf == NULL) + if (hFile == INVALID_HANDLE_VALUE || hFile == (HANDLE)-2 || buf == NULL) { errno = EINVAL; return -1; } - /* - * Check if the fileno is a data stream. If so, unless it has been - * redirected to a file, getting information through its HANDLE will fail, - * so emulate its stat information in the most appropriate way and return - * it instead. + fileType = GetFileType(hFile); + lastError = GetLastError(); + + /* + * Invoke GetLastError in order to distinguish between a "valid" + * return of FILE_TYPE_UNKNOWN and its return due to a calling error. + * In case of success, GetLastError returns NO_ERROR. */ - if ((fileno == _fileno(stdin) || - fileno == _fileno(stdout) || - fileno == _fileno(stderr)) && - !GetFileInformationByHandle(hFile, &fiData)) + if (fileType == FILE_TYPE_UNKNOWN && lastError != NO_ERROR) { + _dosmaperr(lastError); + return -1; + } + + switch (fileType) { - memset(buf, 0, sizeof(*buf)); - buf->st_mode = _S_IFCHR; - buf->st_dev = fileno; - buf->st_rdev = fileno; - buf->st_nlink = 1; - return 0; + /* The specified file is a disk file */ + case FILE_TYPE_DISK: + return fileinfo_to_stat(hFile, buf); + /* + * The specified file is a socket, + * a named pipe, or an anonymous pipe. + */ + case FILE_TYPE_PIPE: + st_mode = _S_IFIFO; + break; + /* + * The specified file is a character file, + * typically an LPT device or a console + */ + case FILE_TYPE_CHAR: + /* + * Unused flag and unknown file type + */ + case FILE_TYPE_REMOTE: + case FILE_TYPE_UNKNOWN: + st_mode = _S_IFCHR; + break; + default: + errno = EINVAL; + return -1; } - return fileinfo_to_stat(hFile, buf); + memset(buf, 0, sizeof(*buf)); + buf->st_mode = st_mode; + buf->st_dev = fileno; + buf->st_rdev = fileno; + buf->st_nlink = 1; + return 0; } #endif /* WIN32 */
base-commit: e52f8b301ed54aac5162b185b43f5f1e44b6b17e