|
11 | 11 | *as a service.
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $PostgreSQL: pgsql/src/port/copydir.c,v 1.24 2010/01/02 16:58:13 momjian Exp $ |
| 14 | + * $PostgreSQL: pgsql/src/port/copydir.c,v 1.25 2010/02/14 17:50:52 stark Exp $ |
15 | 15 | *
|
16 | 16 | *-------------------------------------------------------------------------
|
17 | 17 | */
|
@@ -50,6 +50,7 @@ copydir(char *fromdir, char *todir, bool recurse)
|
50 | 50 | {
|
51 | 51 | DIR*xldir;
|
52 | 52 | structdirent*xlde;
|
| 53 | +intdirfd; |
53 | 54 | charfromfile[MAXPGPATH];
|
54 | 55 | chartofile[MAXPGPATH];
|
55 | 56 |
|
@@ -91,6 +92,26 @@ copydir(char *fromdir, char *todir, bool recurse)
|
91 | 92 | }
|
92 | 93 |
|
93 | 94 | FreeDir(xldir);
|
| 95 | + |
| 96 | +/* |
| 97 | + * fsync the directory to make sure not just the data but also the |
| 98 | + * new directory file entries have reached the disk. While needed |
| 99 | + * by most filesystems, the window got bigger with newer ones like |
| 100 | + * ext4. |
| 101 | + */ |
| 102 | +dirfd=BasicOpenFile(todir, |
| 103 | +O_RDONLY |PG_BINARY, |
| 104 | +S_IRUSR |S_IWUSR); |
| 105 | +if(dirfd==-1) |
| 106 | +ereport(ERROR, |
| 107 | + (errcode_for_file_access(), |
| 108 | +errmsg("could not open directory for fsync \"%s\": %m",todir))); |
| 109 | + |
| 110 | +if(pg_fsync(dirfd)==-1) |
| 111 | +ereport(ERROR, |
| 112 | +(errcode_for_file_access(), |
| 113 | +errmsg("could not fsync directory \"%s\": %m",todir))); |
| 114 | +close(dirfd); |
94 | 115 | }
|
95 | 116 |
|
96 | 117 | /*
|
|