[notmuch] [PATCH] notmuch-new: Check for non-fatal errors from stat()

2009-11-27 Thread Carl Worth
On Fri, 27 Nov 2009 13:50:11 +, Chris Wilson  
wrote:
> 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.

Thanks! Pushed.

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH] notmuch-new: Check for non-fatal errors from stat()

2009-11-27 Thread Chris Wilson
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