mu: add '--lazy-check' option for indexing
Add an option --lazy-check to ignore any directories that don't have their ctime changed since the last indexing operation. There are a few corner-cases (such as editing a message outside mu's control) where this might miss a change, but apart from that, makes indexing in for a maildir (and its sub-maildirs) almost a no-op if there were no changes.
This commit is contained in:
@ -248,21 +248,20 @@ process_file (const char* fullpath, const gchar* mdir,
|
||||
* determine if path is a maildir leaf-dir; ie. if it's 'cur' or 'new'
|
||||
* (we're skipping 'tmp' for obvious reasons)
|
||||
*/
|
||||
G_GNUC_CONST static gboolean
|
||||
is_maildir_new_or_cur (const char *path)
|
||||
gboolean
|
||||
mu_maildir_is_leaf_dir (const char *path)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
g_return_val_if_fail (path, FALSE);
|
||||
|
||||
/* path is the full path; it cannot possibly be shorter
|
||||
* than 4 for a maildir (/cur or /new) */
|
||||
len = strlen (path);
|
||||
len = path ? strlen (path) : 0;
|
||||
if (G_UNLIKELY(len < 4))
|
||||
return FALSE;
|
||||
|
||||
/* optimization; one further idea would be cast the 4 bytes to an integer
|
||||
* and compare that -- need to think about alignment, endianness */
|
||||
/* optimization; one further idea would be cast the 4 bytes to an
|
||||
* integer and compare that -- need to think about alignment,
|
||||
* endianness */
|
||||
|
||||
if (path[len - 4] == G_DIR_SEPARATOR &&
|
||||
path[len - 3] == 'c' &&
|
||||
@ -415,7 +414,7 @@ process_dir_entry (const char* path, const char* mdir, struct dirent *entry,
|
||||
|
||||
switch (d_type) {
|
||||
case DT_REG: /* we only want files in cur/ and new/ */
|
||||
if (!is_maildir_new_or_cur (path))
|
||||
if (!mu_maildir_is_leaf_dir (path))
|
||||
return MU_OK;
|
||||
|
||||
return process_file (fullpath, mdir, cb_msg, data);
|
||||
@ -522,7 +521,7 @@ process_dir (const char* path, const char* mdir,
|
||||
gboolean full, void *data)
|
||||
{
|
||||
MuError result;
|
||||
DIR* dir;
|
||||
DIR* dir;
|
||||
|
||||
/* if it has a noindex file, we ignore this dir */
|
||||
if (dir_contains_file (path, MU_MAILDIR_NOINDEX_FILE) ||
|
||||
@ -531,27 +530,30 @@ process_dir (const char* path, const char* mdir,
|
||||
return MU_OK;
|
||||
}
|
||||
|
||||
if (dir_cb) {
|
||||
MuError rv;
|
||||
rv = dir_cb (path, TRUE/*enter*/, data);
|
||||
/* ignore this dir; not necessarily an _error_, dir might
|
||||
* be up-to-date and return MU_IGNORE */
|
||||
if (rv == MU_IGNORE)
|
||||
return MU_OK;
|
||||
else if (rv != MU_OK)
|
||||
return rv;
|
||||
}
|
||||
|
||||
dir = opendir (path);
|
||||
if (!dir) {
|
||||
g_warning ("cannot access %s: %s", path, strerror(errno));
|
||||
return MU_OK;
|
||||
}
|
||||
|
||||
if (dir_cb) {
|
||||
MuError rv;
|
||||
rv = dir_cb (path, TRUE, data);
|
||||
if (rv != MU_OK) {
|
||||
closedir (dir);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
result = process_dir_entries (dir, path, mdir, msg_cb, dir_cb, full, data);
|
||||
result = process_dir_entries (dir, path, mdir, msg_cb, dir_cb,
|
||||
full, data);
|
||||
closedir (dir);
|
||||
|
||||
/* only run dir_cb if it exists and so far, things went ok */
|
||||
if (dir_cb && result == MU_OK)
|
||||
return dir_cb (path, FALSE, data);
|
||||
return dir_cb (path, FALSE/*leave*/, data);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -798,15 +800,16 @@ mu_maildir_get_new_path (const char *oldpath, const char *new_mdir,
|
||||
if (new_name)
|
||||
mfile = get_new_basename ();
|
||||
else {
|
||||
/* determine the name of the mailfile, stripped of its flags, as well
|
||||
* as any custom (non-standard) flags */
|
||||
/* determine the name of the mailfile, stripped of its flags, as
|
||||
* well as any custom (non-standard) flags */
|
||||
char *cur;
|
||||
mfile = g_path_get_basename (oldpath);
|
||||
for (cur = &mfile[strlen(mfile)-1]; cur > mfile; --cur) {
|
||||
if ((*cur == ':' || *cur == '!') &&
|
||||
(cur[1] == '2' && cur[2] == ',')) {
|
||||
/* get the custom flags (if any) */
|
||||
custom_flags = mu_flags_custom_from_str (cur + 3);
|
||||
custom_flags =
|
||||
mu_flags_custom_from_str (cur + 3);
|
||||
cur[0] = '\0'; /* strip the flags */
|
||||
break;
|
||||
}
|
||||
@ -839,8 +842,6 @@ get_file_size (const char* path)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
msg_move_check_pre (const gchar *src, const gchar *dst, GError **err)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user