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

Commitf1d7516

Browse files
committed
Backport "Expose fsync_fname as a public API".
Backport commitb0a48e9 back to 9.0to allow back-patching another fix that uses fsync_fname.
1 parente8837fc commitf1d7516

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed

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

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939

4040
staticvoidcopy_file(char*fromfile,char*tofile);
41-
staticvoidfsync_fname(char*fname,boolisdir);
4241

4342

4443
/*
@@ -214,59 +213,3 @@ copy_file(char *fromfile, char *tofile)
214213

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

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,3 +1948,59 @@ RemovePgTempFilesInDir(const char *tmpdirname)
19481948

19491949
FreeDir(temp_dir);
19501950
}
1951+
1952+
1953+
/*
1954+
* fsync a file
1955+
*
1956+
* Try to fsync directories but ignore errors that indicate the OS
1957+
* just doesn't allow/require fsyncing directories.
1958+
*/
1959+
void
1960+
fsync_fname(char*fname,boolisdir)
1961+
{
1962+
intfd;
1963+
intreturncode;
1964+
1965+
/*
1966+
* Some OSs require directories to be opened read-only whereas other
1967+
* systems don't allow us to fsync files opened read-only; so we need both
1968+
* cases here
1969+
*/
1970+
if (!isdir)
1971+
fd=BasicOpenFile(fname,
1972+
O_RDWR |PG_BINARY,
1973+
S_IRUSR |S_IWUSR);
1974+
else
1975+
fd=BasicOpenFile(fname,
1976+
O_RDONLY |PG_BINARY,
1977+
S_IRUSR |S_IWUSR);
1978+
1979+
/*
1980+
* Some OSs don't allow us to open directories at all (Windows returns
1981+
* EACCES)
1982+
*/
1983+
if (fd<0&&isdir&& (errno==EISDIR||errno==EACCES))
1984+
return;
1985+
1986+
elseif (fd<0)
1987+
ereport(ERROR,
1988+
(errcode_for_file_access(),
1989+
errmsg("could not open file \"%s\": %m",fname)));
1990+
1991+
returncode=pg_fsync(fd);
1992+
1993+
/* Some OSs don't allow us to fsync directories at all */
1994+
if (returncode!=0&&isdir&&errno==EBADF)
1995+
{
1996+
close(fd);
1997+
return;
1998+
}
1999+
2000+
if (returncode!=0)
2001+
ereport(ERROR,
2002+
(errcode_for_file_access(),
2003+
errmsg("could not fsync file \"%s\": %m",fname)));
2004+
2005+
close(fd);
2006+
}

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extern intpg_fsync_no_writethrough(int fd);
9999
externintpg_fsync_writethrough(intfd);
100100
externintpg_fdatasync(intfd);
101101
externintpg_flush_data(intfd,off_toffset,off_tamount);
102+
externvoidfsync_fname(char*fname,boolisdir);
102103

103104
/* Filename components for OpenTemporaryFile */
104105
#definePG_TEMP_FILES_DIR "pgsql_tmp"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp