[PATCH 05/11] cli/insert: clean up sync_dir

Jani Nikula jani at nikula.org
Mon Sep 22 02:54:56 PDT 2014


Clarify the code slightly, improve error messages. Apart from the
error message changes, no functional changes.
---
 notmuch-insert.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index 5d47806..7375c54 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -67,20 +67,21 @@ safe_gethostname (char *hostname, size_t len)
 static notmuch_bool_t
 sync_dir (const char *dir)
 {
-    notmuch_bool_t ret;
-    int fd;
+    int fd, r;
 
     fd = open (dir, O_RDONLY);
     if (fd == -1) {
-	fprintf (stderr, "Error: open() dir failed: %s\n", strerror (errno));
+	fprintf (stderr, "Error: open %s: %s\n", dir, strerror (errno));
 	return FALSE;
     }
-    ret = (fsync (fd) == 0);
-    if (! ret) {
-	fprintf (stderr, "Error: fsync() dir failed: %s\n", strerror (errno));
-    }
+
+    r = fsync (fd);
+    if (r)
+	fprintf (stderr, "Error: fsync %s: %s\n", dir, strerror (errno));
+
     close (fd);
-    return ret;
+
+    return r == 0;
 }
 
 /*
-- 
1.7.2.5



More information about the notmuch mailing list