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

Commitcc52d5b

Browse files
committed
Expose fsync_fname as a public API.
Andres Freund
1 parent0c66a22 commitcc52d5b

File tree

3 files changed

+57
-59
lines changed

3 files changed

+57
-59
lines changed

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
#include"miscadmin.h"
2828

2929

30-
staticvoidfsync_fname(char*fname,boolisdir);
31-
32-
3330
/*
3431
* copydir: copy a directory
3532
*
@@ -207,59 +204,3 @@ copy_file(char *fromfile, char *tofile)
207204

208205
pfree(buffer);
209206
}
210-
211-
212-
/*
213-
* fsync a file
214-
*
215-
* Try to fsync directories but ignore errors that indicate the OS
216-
* just doesn't allow/require fsyncing directories.
217-
*/
218-
staticvoid
219-
fsync_fname(char*fname,boolisdir)
220-
{
221-
intfd;
222-
intreturncode;
223-
224-
/*
225-
* Some OSs require directories to be opened read-only whereas other
226-
* systems don't allow us to fsync files opened read-only; so we need both
227-
* cases here
228-
*/
229-
if (!isdir)
230-
fd=OpenTransientFile(fname,
231-
O_RDWR |PG_BINARY,
232-
S_IRUSR |S_IWUSR);
233-
else
234-
fd=OpenTransientFile(fname,
235-
O_RDONLY |PG_BINARY,
236-
S_IRUSR |S_IWUSR);
237-
238-
/*
239-
* Some OSs don't allow us to open directories at all (Windows returns
240-
* EACCES)
241-
*/
242-
if (fd<0&&isdir&& (errno==EISDIR||errno==EACCES))
243-
return;
244-
245-
elseif (fd<0)
246-
ereport(ERROR,
247-
(errcode_for_file_access(),
248-
errmsg("could not open file \"%s\": %m",fname)));
249-
250-
returncode=pg_fsync(fd);
251-
252-
/* Some OSs don't allow us to fsync directories at all */
253-
if (returncode!=0&&isdir&&errno==EBADF)
254-
{
255-
CloseTransientFile(fd);
256-
return;
257-
}
258-
259-
if (returncode!=0)
260-
ereport(ERROR,
261-
(errcode_for_file_access(),
262-
errmsg("could not fsync file \"%s\": %m",fname)));
263-
264-
CloseTransientFile(fd);
265-
}

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,62 @@ pg_flush_data(int fd, off_t offset, off_t amount)
384384
}
385385

386386

387+
/*
388+
* fsync_fname -- fsync a file or directory, handling errors properly
389+
*
390+
* Try to fsync a file or directory. When doing the latter, ignore errors that
391+
* indicate the OS just doesn't allow/require fsyncing directories.
392+
*/
393+
void
394+
fsync_fname(char*fname,boolisdir)
395+
{
396+
intfd;
397+
intreturncode;
398+
399+
/*
400+
* Some OSs require directories to be opened read-only whereas other
401+
* systems don't allow us to fsync files opened read-only; so we need both
402+
* cases here
403+
*/
404+
if (!isdir)
405+
fd=OpenTransientFile(fname,
406+
O_RDWR |PG_BINARY,
407+
S_IRUSR |S_IWUSR);
408+
else
409+
fd=OpenTransientFile(fname,
410+
O_RDONLY |PG_BINARY,
411+
S_IRUSR |S_IWUSR);
412+
413+
/*
414+
* Some OSs don't allow us to open directories at all (Windows returns
415+
* EACCES)
416+
*/
417+
if (fd<0&&isdir&& (errno==EISDIR||errno==EACCES))
418+
return;
419+
420+
elseif (fd<0)
421+
ereport(ERROR,
422+
(errcode_for_file_access(),
423+
errmsg("could not open file \"%s\": %m",fname)));
424+
425+
returncode=pg_fsync(fd);
426+
427+
/* Some OSs don't allow us to fsync directories at all */
428+
if (returncode!=0&&isdir&&errno==EBADF)
429+
{
430+
CloseTransientFile(fd);
431+
return;
432+
}
433+
434+
if (returncode!=0)
435+
ereport(ERROR,
436+
(errcode_for_file_access(),
437+
errmsg("could not fsync file \"%s\": %m",fname)));
438+
439+
CloseTransientFile(fd);
440+
}
441+
442+
387443
/*
388444
* InitFileAccess --- initialize this module during backend startup
389445
*

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ extern intpg_fsync_no_writethrough(int fd);
113113
externintpg_fsync_writethrough(intfd);
114114
externintpg_fdatasync(intfd);
115115
externintpg_flush_data(intfd,off_toffset,off_tamount);
116+
externvoidfsync_fname(char*fname,boolisdir);
116117

117118
/* Filename components for OpenTemporaryFile */
118119
#definePG_TEMP_FILES_DIR "pgsql_tmp"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp