From 2e07e68630aa5a530e5770b113258797d9ff8304 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 9 Sep 2012 12:18:14 +0200 Subject: [PATCH] call fdatasync() after updating .uidvalidity files they must be flushed before the file system meta data, as otherwise we may end up with duplicate UIDs after a system crash. --- src/drv_maildir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/drv_maildir.c b/src/drv_maildir.c index a9f5790..771cf48 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -42,6 +42,10 @@ # define LEGACY_FLOCK 1 #endif +#ifndef _POSIX_SYNCHRONIZED_IO +# define fdatasync fsync +#endif + #ifdef USE_DB #include #endif /* USE_DB */ @@ -428,7 +432,7 @@ maildir_store_uid( maildir_store_t *ctx ) n = sprintf( buf, "%d\n%d\n", ctx->gen.uidvalidity, ctx->nuid ); lseek( ctx->uvfd, 0, SEEK_SET ); - if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n )) { + if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || fdatasync( ctx->uvfd )) { error( "Maildir error: cannot write UIDVALIDITY.\n" ); return DRV_BOX_BAD; }