dovecot-1.1: Moved fdatasync_path() to a global function.

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 4 06:28:07 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/d2b10facb504
changeset: 7329:d2b10facb504
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 04 03:47:57 2008 +0200
description:
Moved fdatasync_path() to a global function.

diffstat:

4 files changed, 38 insertions(+), 21 deletions(-)
src/lib-storage/index/maildir/maildir-save.c |   28 ++++++--------------------
src/lib/Makefile.am                          |    2 +
src/lib/fdatasync-path.c                     |   22 ++++++++++++++++++++
src/lib/fdatasync-path.h                     |    7 ++++++

diffs (112 lines):

diff -r e0e212e7deeb -r d2b10facb504 src/lib-storage/index/maildir/maildir-save.c
--- a/src/lib-storage/index/maildir/maildir-save.c	Mon Mar 03 08:59:07 2008 +0200
+++ b/src/lib-storage/index/maildir/maildir-save.c	Tue Mar 04 03:47:57 2008 +0200
@@ -7,6 +7,7 @@
 #include "istream.h"
 #include "istream-crlf.h"
 #include "ostream.h"
+#include "fdatasync-path.h"
 #include "str.h"
 #include "index-mail.h"
 #include "maildir-storage.h"
@@ -571,25 +572,6 @@ maildir_transaction_unlink_copied_files(
 	ctx->files = pos;
 }
 
-static int fdatasync_path(const char *path)
-{
-	int fd, ret = 0;
-
-	/* Directories need to be opened as read-only.
-	   fsync() doesn't appear to care about it. */
-	fd = open(path, O_RDONLY);
-	if (fd == -1) {
-		i_error("open(%s) failed: %m", path);
-		return -1;
-	}
-	if (fdatasync(fd) < 0) {
-		i_error("fdatasync(%s) failed: %m", path);
-		ret = -1;
-	}
-	(void)close(fd);
-	return ret;
-}
-
 static int maildir_transaction_fsync_dirs(struct maildir_save_context *ctx,
 					  bool new_changed, bool cur_changed)
 {
@@ -597,12 +579,16 @@ static int maildir_transaction_fsync_dir
 		return 0;
 
 	if (new_changed) {
-		if (fdatasync_path(ctx->newdir) < 0)
+		if (fdatasync_path(ctx->newdir) < 0) {
+			i_error("fdatasync_path(%s) failed: %m", ctx->newdir);
 			return -1;
+		}
 	}
 	if (cur_changed) {
-		if (fdatasync_path(ctx->curdir) < 0)
+		if (fdatasync_path(ctx->curdir) < 0) {
+			i_error("fdatasync_path(%s) failed: %m", ctx->curdir);
 			return -1;
+		}
 	}
 	return 0;
 }
diff -r e0e212e7deeb -r d2b10facb504 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Mon Mar 03 08:59:07 2008 +0200
+++ b/src/lib/Makefile.am	Tue Mar 04 03:47:57 2008 +0200
@@ -22,6 +22,7 @@ liblib_a_SOURCES = \
 	failures.c \
 	fd-close-on-exec.c \
 	fd-set-nonblock.c \
+	fdatasync-path.c \
 	fdpass.c \
 	file-cache.c \
 	file-copy.c \
@@ -120,6 +121,7 @@ headers = \
 	failures.h \
 	fd-close-on-exec.h \
 	fd-set-nonblock.h \
+	fdatasync-path.h \
 	fdpass.h \
 	file-cache.h \
 	file-copy.h \
diff -r e0e212e7deeb -r d2b10facb504 src/lib/fdatasync-path.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/fdatasync-path.c	Tue Mar 04 03:47:57 2008 +0200
@@ -0,0 +1,22 @@
+/* Copyright (c) 2008 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "fdatasync-path.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+int fdatasync_path(const char *path)
+{
+	int fd, ret = 0;
+
+	/* Directories need to be opened as read-only.
+	   fsync() doesn't appear to care about it. */
+	fd = open(path, O_RDONLY);
+	if (fd == -1)
+		return -1;
+	if (fdatasync(fd) < 0)
+		ret = -1;
+	(void)close(fd);
+	return ret;
+}
diff -r e0e212e7deeb -r d2b10facb504 src/lib/fdatasync-path.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/fdatasync-path.h	Tue Mar 04 03:47:57 2008 +0200
@@ -0,0 +1,7 @@
+#ifndef FDATASYNC_PATH_H
+#define FDATASYNC_PATH_H
+
+/* Open and fdatasync() the path. Works for files and directories. */
+int fdatasync_path(const char *path);
+
+#endif


More information about the dovecot-cvs mailing list