pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_ftruncate hardcodes length=0 but only under windows
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2023-01-06 72aea955d4 f60acde869 af209b7893  Fix pg_truncate() on Windows.
* pg_ftruncate hardcodes length=0 but only under windows
@ 2023-01-06 03:16  Justin Pryzby <pryzby@telsasoft.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Justin Pryzby @ 2023-01-06 03:16 UTC (permalink / raw)
  To: Thomas Munro <thomas.munro@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org

57faaf376 added pg_truncate(const char *path, off_t length), but
"length" is ignored under WIN32 and the file is unconditionally
truncated to 0.

There's no live bug, since the only caller passes 0:

| src/backend/storage/smgr/md.c:  ret = pg_truncate(path, 0);

But I guess extension users could be unhappy under win32, so maybe a fix
should be backpatched.

inline patch 1: src/backend/storage/file/fd.c (+1/-1 lines) download inline-1.patchdiff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index d4a46f01583..926d000f2ea 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -638,7 +638,7 @@ pg_truncate(const char *path, off_t length) fd = OpenTransientFile(path, O_RDWR | PG_BINARY); if (fd >= 0) { - ret = ftruncate(fd, 0); + ret = ftruncate(fd, length); save_errno = errno; CloseTransientFile(fd); errno = save_errno;
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: pg_ftruncate hardcodes length=0 but only under windows
@ 2023-01-06 04:07  Thomas Munro <thomas.munro@gmail.com>
  parent: Justin Pryzby <pryzby@telsasoft.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Thomas Munro @ 2023-01-06 04:07 UTC (permalink / raw)
  To: Justin Pryzby <pryzby@telsasoft.com>; +Cc: pgsql-hackers@lists.postgresql.org

On Fri, Jan 6, 2023 at 4:16 PM Justin Pryzby <pryzby@telsasoft.com> wrote:
> -               ret = ftruncate(fd, 0);
> +               ret = ftruncate(fd, length);

Oops.  Right.  Thanks, pushed.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-01-06 04:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 03:16 pg_ftruncate hardcodes length=0 but only under windows Justin Pryzby <pryzby@telsasoft.com>
2023-01-06 04:07 ` Thomas Munro <thomas.munro@gmail.com>

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