File tree Expand file tree Collapse file tree 3 files changed +57
-57
lines changed Expand file tree Collapse file tree 3 files changed +57
-57
lines changed Original file line number Diff line number Diff line change 38
38
39
39
40
40
static void copy_file (char * fromfile , char * tofile );
41
- static void fsync_fname (char * fname , bool isdir );
42
41
43
42
44
43
/*
@@ -214,59 +213,3 @@ copy_file(char *fromfile, char *tofile)
214
213
215
214
pfree (buffer );
216
215
}
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
- static void
226
- fsync_fname (char * fname , bool isdir )
227
- {
228
- int fd ;
229
- int returncode ;
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
- else if (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
- }
Original file line number Diff line number Diff line change @@ -1948,3 +1948,59 @@ RemovePgTempFilesInDir(const char *tmpdirname)
1948
1948
1949
1949
FreeDir (temp_dir );
1950
1950
}
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 , bool isdir )
1961
+ {
1962
+ int fd ;
1963
+ int returncode ;
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
+ else if (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
+ }
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ extern int pg_fsync_no_writethrough(int fd);
99
99
extern int pg_fsync_writethrough (int fd );
100
100
extern int pg_fdatasync (int fd );
101
101
extern int pg_flush_data (int fd , off_t offset , off_t amount );
102
+ extern void fsync_fname (char * fname , bool isdir );
102
103
103
104
/* Filename components for OpenTemporaryFile */
104
105
#define PG_TEMP_FILES_DIR "pgsql_tmp"
You can’t perform that action at this time.
0 commit comments