From af209b7893f45af04f1b6f6304e9882069111da7 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 6 Jan 2023 16:38:46 +1300 Subject: [PATCH] Fix pg_truncate() on Windows. Commit 57faaf376 added pg_truncate(const char *path, off_t length), but "length" was ignored under WIN32 and the file was unconditionally truncated to 0. There was no live bug, since the only caller passes 0. Fix, and back-patch to 14 where the function arrived. Author: Justin Pryzby Discussion: https://postgr.es/m/20230106031652.GR3109%40telsasoft.com --- src/backend/storage/file/fd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index e76daff495..3933c06ecc 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -642,7 +642,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;