From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A1653429E35 for ; Sat, 19 Jan 2013 16:52:00 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xJLePGmGwTCx for ; Sat, 19 Jan 2013 16:51:59 -0800 (PST) Received: from mail-pb0-f52.google.com (mail-pb0-f52.google.com [209.85.160.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2C49D429E37 for ; Sat, 19 Jan 2013 16:51:47 -0800 (PST) Received: by mail-pb0-f52.google.com with SMTP id ro2so2672673pbb.25 for ; Sat, 19 Jan 2013 16:51:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=PqF56msYY/gsLbfldKQPpe9DCjP3k7D6m4wfAljZwkM=; b=BdyG3CoifYQyXeG53uNGZ9AhhHc2QqDvw3k93Nen5qa5l2K8KslBeDjgjfi6/e08ak QXg3N1Iie8tUNqzj9mp/CzSiw2xpXPmL4Ieze53BnCz/XagYUe7UEAZ2Ng2D5o19LRAr DLHIWMfbOgTHCI0zpsQ2qxSCrgCoj8vVGLjKflbpsP69JmvLCgudGyApCTvCiiGNNOPe MVLQNbQV0j+5QwI6JaDxi5ALheVQPY3QnA9r3EDrHijzG++Gk01C5X+c2j71F3ZRoZEX HDudKJ1wgkAZEPh5qM/Mk6yeZ+BezNvST+zv4tjiEjoH5NBTZZ9ulwTR5Mx8nkX0eA+H RN7w== X-Received: by 10.69.16.100 with SMTP id fv4mr18371390pbd.135.1358643106300; Sat, 19 Jan 2013 16:51:46 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id nt5sm5796332pbb.59.2013.01.19.16.51.44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 19 Jan 2013 16:51:45 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v3 15/20] insert: fsync parent directory after mkdir Date: Sun, 20 Jan 2013 11:49:59 +1100 Message-Id: <1358643004-14522-16-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com> References: <1358643004-14522-1-git-send-email-novalazy@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Jan 2013 00:52:01 -0000 After creating a subdirectory, fsync on its parent directory for durability. --- notmuch-insert.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index c4d5e75..8012eb4 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -82,9 +82,21 @@ sync_dir (const char *dir) static notmuch_bool_t make_directory (char *path, int mode) { + notmuch_bool_t ret; + char *slash; + if (mkdir (path, mode) != 0) return (errno == EEXIST); - return TRUE; + + /* Sync the parent directory for durability. */ + ret = TRUE; + slash = strrchr (path, '/'); + if (slash) { + *slash = '\0'; + ret = sync_dir (path); + *slash = '/'; + } + return ret; } /* Make the given directory including its parent directories as necessary. -- 1.7.12.1