* as a service.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/copydir.c,v 1.16.2.1 2008/03/31 01:32:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/port/copydir.c,v 1.16.2.2 2010/02/14 17:50:34 stark Exp $
*
*-------------------------------------------------------------------------
*/
{
DIR *xldir;
struct dirent *xlde;
+ int dirfd;
char fromfile[MAXPGPATH];
char tofile[MAXPGPATH];
}
FreeDir(xldir);
+
+ /*
+ * fsync the directory to make sure not just the data but also the
+ * new directory file entries have reached the disk. While needed
+ * by most filesystems, the window got bigger with newer ones like
+ * ext4.
+ */
+ dirfd = BasicOpenFile(todir,
+ O_RDONLY | PG_BINARY,
+ S_IRUSR | S_IWUSR);
+ if(dirfd == -1)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not open directory for fsync \"%s\": %m", todir)));
+
+ if(pg_fsync(dirfd) == -1)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not fsync directory \"%s\": %m", todir)));
+ close(dirfd);
}
/*