remove some dead code

This commit is contained in:
Dirk-Jan C. Binnema
2021-01-20 11:18:33 +02:00
parent 362c53a7e7
commit 98744c66f7
14 changed files with 49 additions and 1092 deletions

View File

@ -207,43 +207,6 @@ Mu::mu_maildir_link (const char* src, const char *targetpath, GError **err)
}
static MuError
process_dir (const char* path, const char *mdir,
MuMaildirWalkMsgCallback msg_cb,
MuMaildirWalkDirCallback dir_cb, gboolean full,
void *data);
static MuError
process_file (const char* fullpath, const char* mdir,
MuMaildirWalkMsgCallback msg_cb, void *data)
{
MuError result;
struct stat statbuf;
if (!msg_cb)
return MU_OK;
if (G_UNLIKELY(access(fullpath, R_OK) != 0)) {
g_warning ("cannot access %s: %s", fullpath,
strerror(errno));
return MU_ERROR;
}
if (G_UNLIKELY(stat (fullpath, &statbuf) != 0)) {
g_warning ("cannot stat %s: %s", fullpath, strerror(errno));
return MU_ERROR;
}
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)
g_warning ("%s: error in callback (%s)",
__func__, fullpath);
return result;
}
/*
* determine if path is a maildir leaf-dir; ie. if it's 'cur' or 'new'
@ -280,290 +243,6 @@ Mu::mu_maildir_is_leaf_dir (const char *path)
}
/* check if there path contains file; used for checking if there is
* MU_MAILDIR_NOINDEX_FILE or MU_MAILDIR_NOUPDATE_FILE in this
* dir; */
static gboolean
dir_contains_file (const char *path, const char *file)
{
const char* fullpath;
/* static buffer */
fullpath = mu_str_fullpath_s (path, file);
if (access (fullpath, F_OK) == 0)
return TRUE;
else if (G_UNLIKELY(errno != ENOENT && errno != EACCES))
g_warning ("error testing for %s/%s: %s",
fullpath, file, strerror(errno));
return FALSE;
}
static gboolean
is_dotdir_to_ignore (const char* dir)
{
int i;
const char* ignore[] = {
".notmuch",
".nnmaildir",
".#evolution"
}; /* when adding names, check the optimization below */
if (dir[0] != '.')
return FALSE; /* not a dotdir */
if (dir[1] == '\0' || (dir[1] == '.' && dir[2] == '\0'))
return TRUE; /* ignore '.' and '..' */
/* optimization: special dirs have 'n' or '#' in pos 1 */
if (dir[1] != 'n' && dir[1] != '#')
return FALSE; /* not special: don't ignore */
for (i = 0; i != G_N_ELEMENTS(ignore); ++i)
if (strcmp(dir, ignore[i]) == 0)
return TRUE;
return FALSE; /* don't ignore */
}
static gboolean
ignore_dir_entry (struct dirent *entry, unsigned char d_type)
{
if (G_LIKELY(d_type == DT_REG)) {
guint u;
/* ignore emacs tempfiles */
if (entry->d_name[0] == '#')
return TRUE;
/* ignore dovecot metadata */
if (entry->d_name[0] == 'd' &&
strncmp (entry->d_name, "dovecot", 7) == 0)
return TRUE;
/* ignore special files */
if (entry->d_name[0] == '.')
return TRUE;
/* ignore core files */
if (entry->d_name[0] == 'c' &&
strncmp (entry->d_name, "core", 4) == 0)
return TRUE;
/* ignore tmp/backup files; find the last char */
for (u = 0; entry->d_name[u] != '\0'; ++u) {
switch (entry->d_name[u]) {
case '#':
case '~':
/* looks like a backup / tempsave file */
if (entry->d_name[u + 1] == '\0')
return TRUE;
continue;
default:
continue;
}
}
return FALSE; /* other files: don't ignore */
} else if (d_type == DT_DIR)
return is_dotdir_to_ignore (entry->d_name);
else
return TRUE; /* ignore non-normal files, non-dirs */
}
/*
* return the maildir value for the the path - this is the directory
* for the message (with the top-level dir as "/"), and without the
* leaf "/cur" or "/new". In other words, contatenate old_mdir + "/" + dir,
* unless dir is either 'new' or 'cur'. The value will be used in queries.
*/
static char*
get_mdir_for_path (const char *old_mdir, const char *dir)
{
/* if the current dir is not 'new' or 'cur', contatenate
* old_mdir an dir */
if ((dir[0] == 'n' && strcmp(dir, "new") == 0) ||
(dir[0] == 'c' && strcmp(dir, "cur") == 0) ||
(dir[0] == 't' && strcmp(dir, "tmp") == 0))
return strdup (old_mdir ? old_mdir : G_DIR_SEPARATOR_S);
else
return g_strconcat (old_mdir ? old_mdir : "",
G_DIR_SEPARATOR_S, dir, NULL);
}
static MuError
process_dir_entry (const char* path, const char* mdir, struct dirent *entry,
MuMaildirWalkMsgCallback cb_msg,
MuMaildirWalkDirCallback cb_dir,
gboolean full, void *data)
{
const char *fp;
char* fullpath;
unsigned char d_type;
/* we have to copy the buffer from fullpath_s, because it
* returns a static buffer, and we maybe called reentrantly */
fp = mu_str_fullpath_s (path, entry->d_name);
fullpath = g_newa (char, strlen(fp) + 1);
strcpy (fullpath, fp);
d_type = get_dtype(entry, fullpath, FALSE/*stat*/);
/* ignore special files/dirs */
if (ignore_dir_entry (entry, d_type)) {
/* g_debug ("ignoring %s\n", entry->d_name); */
return MU_OK;
}
switch (d_type) {
case DT_REG: /* we only want files in cur/ and new/ */
if (!mu_maildir_is_leaf_dir (path))
return MU_OK;
return process_file (fullpath, mdir, cb_msg, data);
case DT_DIR: {
char *my_mdir;
MuError rv;
/* my_mdir is the search maildir (the dir starting
* with the top-level maildir as /, and without the
* /tmp, /cur, /new */
my_mdir = get_mdir_for_path (mdir, entry->d_name);
rv = process_dir (fullpath, my_mdir, cb_msg, cb_dir, full, data);
g_free (my_mdir);
return rv;
}
default:
return MU_OK; /* ignore other types */
}
}
#ifdef HAVE_STRUCT_DIRENT_D_INO
static int
dirent_cmp (struct dirent *d1, struct dirent *d2)
{
/* we do it his way instead of a simple d1->d_ino - d2->d_ino
* because this way, we don't need 64-bit numbers for the
* actual sorting */
if (d1->d_ino < d2->d_ino)
return -1;
else if (d1->d_ino > d2->d_ino)
return 1;
else
return 0;
}
#endif /*HAVE_STRUCT_DIRENT_D_INO*/
static MuError
process_dir_entries (DIR *dir, const char* path, const char* mdir,
MuMaildirWalkMsgCallback msg_cb,
MuMaildirWalkDirCallback dir_cb,
gboolean full, void *data)
{
MuError result;
GSList *lst, *c;
for (lst = NULL;;) {
struct dirent *entry, *res;
errno = 0;
res = readdir (dir);
if (res) {
entry = (struct dirent*)g_memdup (res, sizeof(struct dirent));
lst = g_slist_prepend (lst, entry);
} else if (errno == 0) {
break;
} else {
g_warning ("error scanning dir: %s", strerror(errno));
return MU_ERROR_FILE;
}
}
/* we sort by inode; this makes things much faster on
* extfs2,3 */
#if HAVE_STRUCT_DIRENT_D_INO
c = lst = g_slist_sort (lst, (GCompareFunc)dirent_cmp);
#endif /*HAVE_STRUCT_DIRENT_D_INO*/
for (c = lst, result = MU_OK; c && result == MU_OK; c = g_slist_next(c))
result = process_dir_entry (path, mdir, (struct dirent*)c->data,
msg_cb, dir_cb, full, data);
g_slist_foreach (lst, (GFunc)g_free, NULL);
g_slist_free (lst);
return result;
}
static MuError
process_dir (const char* path, const char* mdir,
MuMaildirWalkMsgCallback msg_cb, MuMaildirWalkDirCallback dir_cb,
gboolean full, void *data)
{
MuError result;
DIR* dir;
/* if it has a noindex file, we ignore this dir */
if (dir_contains_file (path, MU_MAILDIR_NOINDEX_FILE) ||
(!full && dir_contains_file (path, MU_MAILDIR_NOUPDATE_FILE))) {
g_debug ("found noindex/noupdate: ignoring dir %s", path);
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;
}
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/*leave*/, data);
return result;
}
MuError
Mu::mu_maildir_walk (const char *path, MuMaildirWalkMsgCallback cb_msg,
MuMaildirWalkDirCallback cb_dir, gboolean full,
void *data)
{
MuError rv;
char *mypath;
g_return_val_if_fail (path && cb_msg, MU_ERROR);
g_return_val_if_fail (mu_util_check_dir(path, TRUE, FALSE), MU_ERROR);
/* strip the final / or \ */
mypath = g_strdup (path);
if (mypath[strlen(mypath)-1] == G_DIR_SEPARATOR)
mypath[strlen(mypath)-1] = '\0';
rv = process_dir (mypath, NULL, cb_msg, cb_dir, full, data);
g_free (mypath);
return rv;
}
static gboolean
clear_links (const char *path, DIR *dir)
{