Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id E0F4D431FBC for ; Fri, 27 Nov 2009 05:50:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 UoCvDuqPxYfp for ; Fri, 27 Nov 2009 05:50:24 -0800 (PST) Received: from azsmga101.ch.intel.com (mga07.intel.com [143.182.124.22]) by olra.theworths.org (Postfix) with ESMTP id 2D794431FAE for ; Fri, 27 Nov 2009 05:50:24 -0800 (PST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 27 Nov 2009 05:50:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,301,1257148800"; d="scan'208";a="216298364" Received: from unknown (HELO localhost.localdomain) ([10.255.16.178]) by azsmga001.ch.intel.com with ESMTP; 27 Nov 2009 05:50:14 -0800 From: Chris Wilson To: notmuch@notmuchmail.org Date: Fri, 27 Nov 2009 13:50:11 +0000 Message-Id: <1259329811-6393-1-git-send-email-chris@chris-wilson.co.uk> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <87einkqeyt.fsf@yoom.home.cworth.org> References: <87einkqeyt.fsf@yoom.home.cworth.org> Subject: [notmuch] [PATCH] notmuch-new: Check for non-fatal errors from stat() X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Fri, 27 Nov 2009 13:50:25 -0000 Currently we assume that all errors on stat() a dname is fatal (but continue anyway and report the error at the end). However, some errors reported by stat() such as a missing file or insufficient privilege, we can simply ignore and skip the file. For the others, such as a fault (unlikely!) or out-of-memory, we handle like the other fatal errors by jumping to the end. Signed-off-by: Chris Wilson --- notmuch-new.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 3cde3a7..71224c5 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -168,10 +168,21 @@ add_files_recursive (notmuch_database_t *notmuch, next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); if (stat (next, st)) { + int err = errno; + + switch (err) { + case ENOENT: + /* The file was removed between scandir and now... */ + case EPERM: + case EACCES: + /* We can't read this file so don't add it to the cache. */ + continue; + } + fprintf (stderr, "Error reading %s: %s\n", next, strerror (errno)); ret = NOTMUCH_STATUS_FILE_ERROR; - continue; + goto DONE; } if (S_ISREG (st->st_mode)) { -- 1.6.5.3