* mu-path: implement ignoring dirs that contain a '.noindex' file

This commit is contained in:
Dirk-Jan C. Binnema 2009-12-09 08:53:51 +02:00
parent e15ecb291b
commit 1e2054d19b
1 changed files with 34 additions and 8 deletions

View File

@ -32,7 +32,8 @@
#include "mu-path.h" #include "mu-path.h"
#include "mu-msg-flags.h" #include "mu-msg-flags.h"
#define MU_MAX_FILE_SIZE (15*1000*1000) #define MU_PATH_MAX_FILE_SIZE (15*1000*1000)
#define MU_PATH_NOINDEX_FILE ".noindex"
static MuResult process_dir (const char* path, MuPathWalkMsgCallback msg_cb, static MuResult process_dir (const char* path, MuPathWalkMsgCallback msg_cb,
MuPathWalkDirCallback dir_cb, void *data); MuPathWalkDirCallback dir_cb, void *data);
@ -56,9 +57,9 @@ process_file (const char* fullpath, MuPathWalkMsgCallback cb, void *data)
return MU_ERROR; return MU_ERROR;
} }
if (G_UNLIKELY(statbuf.st_size > MU_MAX_FILE_SIZE)) { if (G_UNLIKELY(statbuf.st_size > MU_PATH_MAX_FILE_SIZE)) {
g_warning ("ignoring because bigger than %d bytes: %s", g_warning ("ignoring because bigger than %d bytes: %s",
MU_MAX_FILE_SIZE, fullpath); MU_PATH_MAX_FILE_SIZE, fullpath);
return MU_ERROR; return MU_ERROR;
} }
@ -74,7 +75,8 @@ process_file (const char* fullpath, MuPathWalkMsgCallback cb, void *data)
} }
/* determine if path is a maildir leaf-dir; ie. if it's 'cur' or 'new' /*
* determine if path is a maildir leaf-dir; ie. if it's 'cur' or 'new'
* (we're skipping 'tmp' for obvious reasons) * (we're skipping 'tmp' for obvious reasons)
*/ */
G_GNUC_CONST static gboolean G_GNUC_CONST static gboolean
@ -100,6 +102,21 @@ is_maildir_new_or_cur (const char *path)
strcmp (sfx + 1, "new") == 0); strcmp (sfx + 1, "new") == 0);
} }
/* check if there is a noindex file (MU_PATH_NOINDEX_FILE) in this dir; */
static gboolean
has_noindex_file (const char *path)
{
char *fname;
fname = g_newa (char, strlen(path) + 1 + strlen(MU_PATH_NOINDEX_FILE) + 1);
sprintf (fname, "%s%c%s", path, G_DIR_SEPARATOR, MU_PATH_NOINDEX_FILE);
if (access (fname, F_OK) == 0)
return TRUE;
else if (errno != ENOENT)
g_warning ("error testing for noindex file: %s", strerror(errno));
return FALSE;
}
static MuResult static MuResult
process_dir_entry (const char* path,struct dirent *entry, process_dir_entry (const char* path,struct dirent *entry,
MuPathWalkMsgCallback cb_msg, MuPathWalkDirCallback cb_dir, MuPathWalkMsgCallback cb_msg, MuPathWalkDirCallback cb_dir,
@ -107,7 +124,8 @@ process_dir_entry (const char* path,struct dirent *entry,
{ {
char* fullpath; char* fullpath;
/* ignore anything starting with a dot */ /* ignore any dir starting with a dot; this will make us
* ignore .notmuch, .nnmaildir etc. */
if (G_UNLIKELY(entry->d_name[0] == '.')) if (G_UNLIKELY(entry->d_name[0] == '.'))
return MU_OK; return MU_OK;
@ -122,8 +140,16 @@ process_dir_entry (const char* path,struct dirent *entry,
return process_file (fullpath, cb_msg, data); return process_file (fullpath, cb_msg, data);
case DT_DIR: case DT_DIR: {
/* if it has a noindex file, we ignore this dir */
if (has_noindex_file (fullpath)) {
g_message ("ignoring dir %s", fullpath);
return MU_OK;
}
return process_dir (fullpath, cb_msg, cb_dir, data); return process_dir (fullpath, cb_msg, cb_dir, data);
}
default: default:
return MU_OK; /* ignore other types */ return MU_OK; /* ignore other types */