Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57faaf3

Browse files
committed
Use truncate(2) where appropriate.
When truncating files by name, use truncate(2). Windows hasn't got it,so keep our previous coding based on ftruncate(2) as a fallback.Discussion:https://postgr.es/m/16663-fe97ccf9932fc800%40postgresql.org
1 parent9f35f94 commit57faaf3

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,33 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
622622
#endif
623623
}
624624

625+
/*
626+
* Truncate a file to a given length by name.
627+
*/
628+
int
629+
pg_truncate(constchar*path,off_tlength)
630+
{
631+
#ifdefWIN32
632+
intsave_errno;
633+
intret;
634+
intfd;
635+
636+
fd=OpenTransientFile(path,O_RDWR |PG_BINARY);
637+
if (fd >=0)
638+
{
639+
ret=ftruncate(fd,0);
640+
save_errno=errno;
641+
CloseTransientFile(fd);
642+
errno=save_errno;
643+
}
644+
else
645+
ret=-1;
646+
647+
returnret;
648+
#else
649+
returntruncate(path,length);
650+
#endif
651+
}
625652

626653
/*
627654
* fsync_fname -- fsync a file or directory, handling errors properly

‎src/backend/storage/smgr/md.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,8 @@ do_truncate(const char *path)
294294
{
295295
intsave_errno;
296296
intret;
297-
intfd;
298297

299-
/* truncate(2) would be easier here, but Windows hasn't got it */
300-
fd=OpenTransientFile(path,O_RDWR |PG_BINARY);
301-
if (fd >=0)
302-
{
303-
ret=ftruncate(fd,0);
304-
save_errno=errno;
305-
CloseTransientFile(fd);
306-
errno=save_errno;
307-
}
308-
else
309-
ret=-1;
298+
ret=pg_truncate(path,0);
310299

311300
/* Log a warning here to avoid repetition in callers. */
312301
if (ret<0&&errno!=ENOENT)

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ extern intpg_fsync_no_writethrough(int fd);
153153
externintpg_fsync_writethrough(intfd);
154154
externintpg_fdatasync(intfd);
155155
externvoidpg_flush_data(intfd,off_toffset,off_tamount);
156+
externintpg_truncate(constchar*path,off_tlength);
156157
externvoidfsync_fname(constchar*fname,boolisdir);
157158
externintfsync_fname_ext(constchar*fname,boolisdir,boolignore_perm,intelevel);
158159
externintdurable_rename(constchar*oldfile,constchar*newfile,intloglevel);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp