mirror of https://github.com/djcb/mu.git
* 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:
parent
91cbdd6b71
commit
62acc7739d
|
@ -35,6 +35,7 @@
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
|
|
||||||
#define MU_LAST_USED_MAILDIR_KEY "last_used_maildir"
|
#define MU_LAST_USED_MAILDIR_KEY "last_used_maildir"
|
||||||
|
#define MU_MAILDIR_WALK_MAX_FILE_SIZE (64*1000*1000)
|
||||||
|
|
||||||
struct _MuIndex {
|
struct _MuIndex {
|
||||||
MuStore *_store;
|
MuStore *_store;
|
||||||
|
@ -174,28 +175,35 @@ run_msg_callback_maybe (MuIndexCallbackData *data)
|
||||||
|
|
||||||
static MuResult
|
static MuResult
|
||||||
on_run_maildir_msg (const char* fullpath, const char* mdir,
|
on_run_maildir_msg (const char* fullpath, const char* mdir,
|
||||||
time_t filestamp, MuIndexCallbackData *data)
|
struct stat *statbuf, MuIndexCallbackData *data)
|
||||||
{
|
{
|
||||||
MuResult result;
|
MuResult result;
|
||||||
gboolean updated;
|
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);
|
result = run_msg_callback_maybe (data);
|
||||||
if (result != MU_OK)
|
if (result != MU_OK)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
/* see if we need to update/insert anything...*/
|
/* see if we need to update/insert anything...
|
||||||
result = insert_or_update_maybe (fullpath, mdir, filestamp, data,
|
* use the ctime, so any status change will be visible (perms,
|
||||||
&updated);
|
* filename etc.)*/
|
||||||
|
result = insert_or_update_maybe (fullpath, mdir, statbuf->st_ctime,
|
||||||
|
data, &updated);
|
||||||
|
|
||||||
/* update statistics */
|
if (result == MU_OK && data && data->_stats) { /* update statistics */
|
||||||
if (data && data->_stats) {
|
|
||||||
++data->_stats->_processed;
|
++data->_stats->_processed;
|
||||||
if (data && data->_stats) {
|
updated ? ++data->_stats->_updated : ++data->_stats->_uptodate;
|
||||||
if (updated)
|
/* if (updated) */
|
||||||
++data->_stats->_updated;
|
/* ++data->_stats->_updated; */
|
||||||
else
|
/* else */
|
||||||
++data->_stats->_uptodate;
|
/* ++data->_stats->_uptodate; */
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -328,11 +336,11 @@ mu_index_run (MuIndex *index, const char* path,
|
||||||
|
|
||||||
static MuResult
|
static MuResult
|
||||||
on_stats_maildir_file (const char *fullpath, const char* mdir,
|
on_stats_maildir_file (const char *fullpath, const char* mdir,
|
||||||
time_t timestamp,
|
struct stat *statbuf,
|
||||||
MuIndexCallbackData *cb_data)
|
MuIndexCallbackData *cb_data)
|
||||||
{
|
{
|
||||||
MuResult result;
|
MuResult result;
|
||||||
|
|
||||||
if (cb_data && cb_data->_idx_msg_cb)
|
if (cb_data && cb_data->_idx_msg_cb)
|
||||||
result = cb_data->_idx_msg_cb (cb_data->_stats,
|
result = cb_data->_idx_msg_cb (cb_data->_stats,
|
||||||
cb_data->_user_data);
|
cb_data->_user_data);
|
||||||
|
|
|
@ -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
|
** 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
|
** under the terms of the GNU General Public License as published by the
|
||||||
|
@ -34,7 +34,6 @@
|
||||||
#include "mu-maildir.h"
|
#include "mu-maildir.h"
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
|
|
||||||
#define MU_MAILDIR_WALK_MAX_FILE_SIZE (32*1000*1000)
|
|
||||||
#define MU_MAILDIR_NOINDEX_FILE ".noindex"
|
#define MU_MAILDIR_NOINDEX_FILE ".noindex"
|
||||||
|
|
||||||
/* On Linux (and some BSD), we have entry->d_type, but some file
|
/* 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;
|
return MU_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (G_UNLIKELY(statbuf.st_size > MU_MAILDIR_WALK_MAX_FILE_SIZE)) {
|
|
||||||
g_warning ("ignoring because bigger than %d bytes: %s",
|
result = (msg_cb)(fullpath, mdir, &statbuf, data);
|
||||||
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);
|
|
||||||
if (result == MU_STOP)
|
if (result == MU_STOP)
|
||||||
g_debug ("callback said 'MU_STOP' for %s", fullpath);
|
g_debug ("callback said 'MU_STOP' for %s", fullpath);
|
||||||
else if (result == MU_ERROR)
|
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 (path && cb_msg, MU_ERROR);
|
||||||
g_return_val_if_fail (mu_util_check_dir(path, TRUE, FALSE), 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 \ */
|
/* strip the final / or \ */
|
||||||
|
mypath = g_strdup (path);
|
||||||
if (mypath[strlen(mypath)-1] == G_DIR_SEPARATOR)
|
if (mypath[strlen(mypath)-1] == G_DIR_SEPARATOR)
|
||||||
mypath[strlen(mypath)-1] = '\0';
|
mypath[strlen(mypath)-1] = '\0';
|
||||||
|
|
||||||
|
|
|
@ -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
|
* called for each message found, with fullpath containing the full
|
||||||
* path to the message, mdir containing the maildir -- that is, when
|
* path to the message, mdir containing the maildir -- that is, when
|
||||||
* indexing ~/Maildir, a message ~/Maildir/foo/bar/cur/msg would have
|
* indexing ~/Maildir, a message ~/Maildir/foo/bar/cur/msg would have
|
||||||
* the maildir "foo/bar". Then, a timestamp of the last modification
|
* the maildir "foo/bar". Then, the information from 'stat' of this
|
||||||
* time of this file, and a user_data pointer
|
* file (see stat(3)), and a user_data pointer
|
||||||
*/
|
*/
|
||||||
typedef MuResult (*MuMaildirWalkMsgCallback)
|
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
|
* MuPathWalkDirCallback -- callback function for mu_path_walk_maildir; see the
|
||||||
|
|
|
@ -163,7 +163,7 @@ dir_cb (const char *fullpath, gboolean enter, WalkData *data)
|
||||||
|
|
||||||
|
|
||||||
static MuResult
|
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)
|
WalkData *data)
|
||||||
{
|
{
|
||||||
++data->_file_count;
|
++data->_file_count;
|
||||||
|
|
Loading…
Reference in New Issue