Skip to content

Commit 591b9b0

Browse files
committed
Use ftruncate() not truncate() in mdunlink. Seems Windows doesn't
support the latter.
1 parent d788c92 commit 591b9b0

File tree

1 file changed

+18
-2
lines changed
  • src/backend/storage/smgr

1 file changed

+18
-2
lines changed

src/backend/storage/smgr/md.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.131 2007/11/15 21:14:38 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.132 2007/11/15 21:49:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -316,7 +316,23 @@ mdunlink(RelFileNode rnode, bool isRedo)
316316
if (isRedo)
317317
ret = unlink(path);
318318
else
319-
ret = truncate(path, 0);
319+
{
320+
/* truncate(2) would be easier here, but Windows hasn't got it */
321+
int fd;
322+
323+
fd = BasicOpenFile(path, O_RDWR | PG_BINARY, 0);
324+
if (fd >= 0)
325+
{
326+
int save_errno;
327+
328+
ret = ftruncate(fd, 0);
329+
save_errno = errno;
330+
close(fd);
331+
errno = save_errno;
332+
}
333+
else
334+
ret = -1;
335+
}
320336
if (ret < 0)
321337
{
322338
if (!isRedo || errno != ENOENT)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy