mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix our Windows stat() emulation to handle file sizes > 4GB.
Hack things so that our idea of "struct stat" is equivalent to Windows' struct __stat64, allowing it to have a wide enough st_size field. Instead of relying on native stat(), use GetFileInformationByHandle(). This avoids a number of issues with Microsoft's multiple and rather slipshod emulations of stat(). We still need to jump through hoops to deal with ERROR_DELETE_PENDING, though :-( Pull the relevant support code out of dirmod.c and put it into its own file, win32stat.c. Still TODO: do we need to do something different with lstat(), rather than treating it identically to stat()? Juan José Santamaría Flecha, reviewed by Emil Iggland; based on prior work by Michael Paquier, Sergey Zubkovsky, and others Discussion: https://postgr.es/m/1803D792815FC24D871C00D17AE95905CF5099@g01jpexmbkw24 Discussion: https://postgr.es/m/15858-9572469fd3b73263@postgresql.org
This commit is contained in:
@ -353,55 +353,3 @@ pgwin32_is_junction(const char *path)
|
||||
return ((attr & FILE_ATTRIBUTE_REPARSE_POINT) == FILE_ATTRIBUTE_REPARSE_POINT);
|
||||
}
|
||||
#endif /* defined(WIN32) && !defined(__CYGWIN__) */
|
||||
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
|
||||
#undef stat
|
||||
|
||||
/*
|
||||
* The stat() function in win32 is not guaranteed to update the st_size
|
||||
* field when run. So we define our own version that uses the Win32 API
|
||||
* to update this field.
|
||||
*/
|
||||
int
|
||||
pgwin32_safestat(const char *path, struct stat *buf)
|
||||
{
|
||||
int r;
|
||||
WIN32_FILE_ATTRIBUTE_DATA attr;
|
||||
|
||||
r = stat(path, buf);
|
||||
if (r < 0)
|
||||
{
|
||||
if (GetLastError() == ERROR_DELETE_PENDING)
|
||||
{
|
||||
/*
|
||||
* File has been deleted, but is not gone from the filesystem yet.
|
||||
* This can happen when some process with FILE_SHARE_DELETE has it
|
||||
* open and it will be fully removed once that handle is closed.
|
||||
* Meanwhile, we can't open it, so indicate that the file just
|
||||
* doesn't exist.
|
||||
*/
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr))
|
||||
{
|
||||
_dosmaperr(GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX no support for large files here, but we don't do that in general on
|
||||
* Win32 yet.
|
||||
*/
|
||||
buf->st_size = attr.nFileSizeLow;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user