* change MuMaildirWalkMsgCallback so it take a full stat buf* instead of just

the ctime; then do the checking for the file size (st_size) in mu-index

  also, update a unit test which was using an invalid MuMaildirWalkMsgCallback
This commit is contained in:
Dirk-Jan C. Binnema 2011-01-15 11:53:18 +02:00
parent 91cbdd6b71
commit 62acc7739d
4 changed files with 30 additions and 34 deletions

View File

@ -35,6 +35,7 @@
#include "mu-util.h"
#define MU_LAST_USED_MAILDIR_KEY "last_used_maildir"
#define MU_MAILDIR_WALK_MAX_FILE_SIZE (64*1000*1000)
struct _MuIndex {
MuStore *_store;
@ -174,28 +175,35 @@ run_msg_callback_maybe (MuIndexCallbackData *data)
static MuResult
on_run_maildir_msg (const char* fullpath, const char* mdir,
time_t filestamp, MuIndexCallbackData *data)
struct stat *statbuf, MuIndexCallbackData *data)
{
MuResult result;
gboolean updated;
/* protect against too big messages */
if (G_UNLIKELY(statbuf->st_size > MU_MAILDIR_WALK_MAX_FILE_SIZE)) {
g_warning ("ignoring because bigger than %d bytes: %s",
MU_MAILDIR_WALK_MAX_FILE_SIZE, fullpath);
return MU_OK; /* not an error */
}
result = run_msg_callback_maybe (data);
if (result != MU_OK)
return result;
/* see if we need to update/insert anything...*/
result = insert_or_update_maybe (fullpath, mdir, filestamp, data,
&updated);
/* see if we need to update/insert anything...
* use the ctime, so any status change will be visible (perms,
* filename etc.)*/
result = insert_or_update_maybe (fullpath, mdir, statbuf->st_ctime,
data, &updated);
/* update statistics */
if (data && data->_stats) {
if (result == MU_OK && data && data->_stats) { /* update statistics */
++data->_stats->_processed;
if (data && data->_stats) {
if (updated)
++data->_stats->_updated;
else
++data->_stats->_uptodate;
}
updated ? ++data->_stats->_updated : ++data->_stats->_uptodate;
/* if (updated) */
/* ++data->_stats->_updated; */
/* else */
/* ++data->_stats->_uptodate; */
}
return result;
@ -328,11 +336,11 @@ mu_index_run (MuIndex *index, const char* path,
static MuResult
on_stats_maildir_file (const char *fullpath, const char* mdir,
time_t timestamp,
struct stat *statbuf,
MuIndexCallbackData *cb_data)
{
MuResult result;
if (cb_data && cb_data->_idx_msg_cb)
result = cb_data->_idx_msg_cb (cb_data->_stats,
cb_data->_user_data);

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2010-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -34,7 +34,6 @@
#include "mu-maildir.h"
#include "mu-str.h"
#define MU_MAILDIR_WALK_MAX_FILE_SIZE (32*1000*1000)
#define MU_MAILDIR_NOINDEX_FILE ".noindex"
/* On Linux (and some BSD), we have entry->d_type, but some file
@ -235,17 +234,8 @@ process_file (const char* fullpath, const gchar* mdir,
return MU_ERROR;
}
if (G_UNLIKELY(statbuf.st_size > MU_MAILDIR_WALK_MAX_FILE_SIZE)) {
g_warning ("ignoring because bigger than %d bytes: %s",
MU_MAILDIR_WALK_MAX_FILE_SIZE, fullpath);
return MU_OK; /* not an error */
}
/*
* use the ctime, so any status change will be visible (perms,
* filename etc.)
*/
result = (msg_cb)(fullpath, mdir, statbuf.st_ctime, data);
result = (msg_cb)(fullpath, mdir, &statbuf, data);
if (result == MU_STOP)
g_debug ("callback said 'MU_STOP' for %s", fullpath);
else if (result == MU_ERROR)
@ -511,10 +501,8 @@ mu_maildir_walk (const char *path, MuMaildirWalkMsgCallback cb_msg,
g_return_val_if_fail (path && cb_msg, MU_ERROR);
g_return_val_if_fail (mu_util_check_dir(path, TRUE, FALSE), MU_ERROR);
/* skip the final slash from dirnames */
mypath = g_strdup (path);
/* strip the final / or \ */
mypath = g_strdup (path);
if (mypath[strlen(mypath)-1] == G_DIR_SEPARATOR)
mypath[strlen(mypath)-1] = '\0';

View File

@ -66,11 +66,11 @@ gboolean mu_maildir_link (const char* src, const char *targetpath, GError **er
* called for each message found, with fullpath containing the full
* path to the message, mdir containing the maildir -- that is, when
* indexing ~/Maildir, a message ~/Maildir/foo/bar/cur/msg would have
* the maildir "foo/bar". Then, a timestamp of the last modification
* time of this file, and a user_data pointer
* the maildir "foo/bar". Then, the information from 'stat' of this
* file (see stat(3)), and a user_data pointer
*/
typedef MuResult (*MuMaildirWalkMsgCallback)
(const char* fullpath, const char* mdir, time_t timestamp, void *user_data);
(const char* fullpath, const char* mdir, struct stat *statinfo, void *user_data);
/**
* MuPathWalkDirCallback -- callback function for mu_path_walk_maildir; see the

View File

@ -163,7 +163,7 @@ dir_cb (const char *fullpath, gboolean enter, WalkData *data)
static MuResult
msg_cb (const char *fullpath, const char* mdir, gboolean enter,
msg_cb (const char *fullpath, const char* mdir, struct stat *statinfo,
WalkData *data)
{
++data->_file_count;