Magnus Hagander wrote:
> Attached is a patch that attempts to fix the issues with stat() not
> properly updating st_size on win32, as reported in this thread:
> http://archives.postgresql.org/pgsql-hackers/2008-03/msg01181.php
>
> It has to have a chance to affect things beyond just the
> pg_relation_size() function, so this patch fixes all cases where we do
> stat() and use the st_size member. It doesn't change all occurances of
> stat() since I didn't want to incur the double filesystem lookups
> unnecessary cases.
>
> Any objections?
Updated version. Seems the problem was that the includes came in the
wrong order - figured that out just after I went to bed :) Here's an
updated patch.
A whole lot simpler patch :-)
//Magnus
Index: include/port.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/include/port.h,v
retrieving revision 1.118
diff -c -r1.118 port.h
*** include/port.h 29 Feb 2008 15:31:33 -0000 1.118
--- include/port.h 10 Apr 2008 11:49:23 -0000
***************
*** 298,303 ****
--- 298,310 ----
#define popen(a,b) _popen(a,b)
#define pclose(a) _pclose(a)
+ /* stat() is not guaranteed to update the size of the file */
+ extern int pgwin32_safestat(const char *path, struct stat *buf);
+ #if !defined(FRONTEND) && !defined(_DIRMOD_C)
+ #include <sys/stat.h>
+ #define stat(a,b) pgwin32_safestat(a,b)
+ #endif
+
/* Missing rand functions */
extern long lrand48(void);
extern void srand48(long seed);
Index: port/dirmod.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/port/dirmod.c,v
retrieving revision 1.51
diff -c -r1.51 dirmod.c
*** port/dirmod.c 1 Jan 2008 19:46:00 -0000 1.51
--- port/dirmod.c 10 Apr 2008 12:06:35 -0000
***************
*** 447,449 ****
--- 447,483 ----
pgfnames_cleanup(filenames);
return false;
}
+
+
+ #ifdef WIN32
+ /*
+ * 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.
+ */
+ #undef stat
+ int
+ pgwin32_safestat(const char *path, struct stat *buf)
+ {
+ int r;
+ WIN32_FILE_ATTRIBUTE_DATA attr;
+
+ r = stat(path, buf);
+ if (r < 0)
+ 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
--
Sent via pgsql-patches mailing list (pgsql-patches@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches