scanner: ignore emacs auto-saves

It's better to _not_ have auto-saves for your draft directory, but if
you do, ignore them at least in mu.

It may still trip up mbsync and friends, but not much we can do about
that.

Clean up the implementation a bit as well.
This commit is contained in:
Dirk-Jan C. Binnema
2024-09-01 18:52:26 +03:00
parent db28b15f99
commit e9ca3ad9f6

View File

@ -98,21 +98,28 @@ ignore_dentry(const dentry_t& dentry)
{ {
const auto d_name{dentry.d_name.c_str()}; const auto d_name{dentry.d_name.c_str()};
/* dotdir? */ /* ignore '.' and '..' and anything starting with '#' (emacs
if (d_name[0] == '\0' || (d_name[1] == '\0' && d_name[0] == '.') || * auto-saves) */
if (d_name[0] == '\0' || d_name[0] == '#' ||
(d_name[1] == '\0' && d_name[0] == '.') ||
(d_name[2] == '\0' && d_name[0] == '.' && d_name[1] == '.')) (d_name[2] == '\0' && d_name[0] == '.' && d_name[1] == '.'))
return true; return true;
if (d_name[0] != 't' && d_name[0] != 'h' && d_name[0] != '.') switch (d_name[0]) {
return false; /* don't ignore */ case 't':
if (::strcmp(d_name, "tmp") == 0)
if (::strcmp(d_name, "tmp") == 0 || ::strcmp(d_name, "hcache.db") == 0) return true; // ignore the tmp dir
return true; // ignore break;
case 'h':
if (d_name[0] == '.') if (::strcmp(d_name, "hcache.db") == 0)
for (auto dname : { "nnmaildir", "notmuch", "noindex", "noupdate"}) return true; // ignore mutt cache
break;
case '.':
for (const auto& dname : {"nnmaildir", "notmuch", "noindex", "noupdate"})
if (::strcmp(d_name + 1, dname) == 0) if (::strcmp(d_name + 1, dname) == 0)
return true; return true; // ignore some known other furniture
break;
}
return false; /* don't ignore */ return false; /* don't ignore */
} }