/**
* rename_filename - Rename the file
- * @param m Notmuch Mailbox data
- * @param old Old filename
- * @param new New filename
- * @param e Email
- * @retval 0 Success
- * @retval -1 Failure
+ * @param m Notmuch Mailbox data
+ * @param old_file Old filename
+ * @param new_file New filename
+ * @param e Email
+ * @retval 0 Success
+ * @retval -1 Failure
*/
-static int rename_filename(struct Mailbox *m, const char *old, const char *new,
- struct Email *e)
+static int rename_filename(struct Mailbox *m, const char *old_file,
+ const char *new_file, struct Email *e)
{
struct NmMboxData *mdata = nm_mdata_get(m);
if (!mdata)
return -1;
notmuch_database_t *db = nm_db_get(m, true);
- if (!db || !new || !old || (access(new, F_OK) != 0))
+ if (!db || !new_file || !old_file || (access(new_file, F_OK) != 0))
return -1;
int rc = -1;
notmuch_filenames_t *ls = NULL;
notmuch_message_t *msg = NULL;
- mutt_debug(LL_DEBUG1, "nm: rename filename, %s -> %s\n", old, new);
+ mutt_debug(LL_DEBUG1, "nm: rename filename, %s -> %s\n", old_file, new_file);
int trans = nm_db_trans_begin(m);
if (trans < 0)
return -1;
- mutt_debug(LL_DEBUG2, "nm: rename: add '%s'\n", new);
+ mutt_debug(LL_DEBUG2, "nm: rename: add '%s'\n", new_file);
#ifdef HAVE_NOTMUCH_DATABASE_INDEX_FILE
- st = notmuch_database_index_file(db, new, NULL, &msg);
+ st = notmuch_database_index_file(db, new_file, NULL, &msg);
#else
- st = notmuch_database_add_message(db, new, &msg);
+ st = notmuch_database_add_message(db, new_file, &msg);
#endif
if ((st != NOTMUCH_STATUS_SUCCESS) && (st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID))
{
- mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", new, (int) st);
+ mutt_debug(LL_DEBUG1, "nm: failed to add '%s' [st=%d]\n", new_file, (int) st);
goto done;
}
- mutt_debug(LL_DEBUG2, "nm: rename: rem '%s'\n", old);
- st = notmuch_database_remove_message(db, old);
+ mutt_debug(LL_DEBUG2, "nm: rename: rem '%s'\n", old_file);
+ st = notmuch_database_remove_message(db, old_file);
switch (st)
{
case NOTMUCH_STATUS_SUCCESS:
mutt_debug(LL_DEBUG2, "nm: rename: syncing duplicate filename\n");
notmuch_message_destroy(msg);
msg = NULL;
- notmuch_database_find_message_by_filename(db, new, &msg);
+ notmuch_database_find_message_by_filename(db, new_file, &msg);
for (ls = notmuch_message_get_filenames(msg);
msg && ls && notmuch_filenames_valid(ls); notmuch_filenames_move_to_next(ls))
const char *path = notmuch_filenames_get(ls);
char newpath[PATH_MAX];
- if (strcmp(new, path) == 0)
+ if (strcmp(new_file, path) == 0)
continue;
mutt_debug(LL_DEBUG2, "nm: rename: syncing duplicate: %s\n", path);
}
notmuch_message_destroy(msg);
msg = NULL;
- notmuch_database_find_message_by_filename(db, new, &msg);
+ notmuch_database_find_message_by_filename(db, new_file, &msg);
st = NOTMUCH_STATUS_SUCCESS;
break;
default:
- mutt_debug(LL_DEBUG1, "nm: failed to remove '%s' [st=%d]\n", old, (int) st);
+ mutt_debug(LL_DEBUG1, "nm: failed to remove '%s' [st=%d]\n", old_file, (int) st);
break;
}
/**
* nm_update_filename - Change the filename
- * @param m Mailbox
- * @param old Old filename
- * @param new New filename
- * @param e Email
- * @retval 0 Success
- * @retval -1 Failure
+ * @param m Mailbox
+ * @param old_file Old filename
+ * @param new_file New filename
+ * @param e Email
+ * @retval 0 Success
+ * @retval -1 Failure
*/
-int nm_update_filename(struct Mailbox *m, const char *old, const char *new, struct Email *e)
+int nm_update_filename(struct Mailbox *m, const char *old_file,
+ const char *new_file, struct Email *e)
{
char buf[PATH_MAX];
struct NmMboxData *mdata = nm_mdata_get(m);
- if (!mdata || !new)
+ if (!mdata || !new_file)
return -1;
- if (!old && e && e->edata)
+ if (!old_file && e && e->edata)
{
email_get_fullpath(e, buf, sizeof(buf));
- old = buf;
+ old_file = buf;
}
- int rc = rename_filename(m, old, new, e);
+ int rc = rename_filename(m, old_file, new_file, e);
nm_db_release(m);
m->mtime.tv_sec = time(NULL);
for (int i = 0; notmuch_messages_valid(msgs) && ((limit == 0) || (i < limit));
notmuch_messages_move_to_next(msgs), i++)
{
- char old[PATH_MAX];
- const char *new = NULL;
-
notmuch_message_t *msg = notmuch_messages_get(msgs);
struct Email *e = get_mutt_email(m, msg);
/* Check to see if the message has moved to a different subdirectory.
* If so, update the associated filename. */
- new = get_message_last_filename(msg);
- email_get_fullpath(e, old, sizeof(old));
+ const char *new_file = get_message_last_filename(msg);
+ char old_file[PATH_MAX];
+ email_get_fullpath(e, old_file, sizeof(old_file));
- if (mutt_str_strcmp(old, new) != 0)
- update_message_path(e, new);
+ if (mutt_str_strcmp(old_file, new_file) != 0)
+ update_message_path(e, new_file);
if (!e->changed)
{
/* if the user hasn't modified the flags on this message, update the
* flags we just detected. */
struct Email tmp = { 0 };
- maildir_parse_flags(&tmp, new);
+ maildir_parse_flags(&tmp, new_file);
maildir_update_flags(m, e, &tmp);
}
for (int i = 0; i < m->msg_count; i++)
{
- char old[PATH_MAX], new[PATH_MAX];
+ char old_file[PATH_MAX], new_file[PATH_MAX];
struct Email *e = m->emails[i];
struct NmEmailData *edata = e->edata;
if (!m->quiet)
mutt_progress_update(&progress, i, -1);
- *old = '\0';
- *new = '\0';
+ *old_file = '\0';
+ *new_file = '\0';
if (edata->oldpath)
{
- mutt_str_strfcpy(old, edata->oldpath, sizeof(old));
- old[sizeof(old) - 1] = '\0';
- mutt_debug(LL_DEBUG2, "nm: fixing obsolete path '%s'\n", old);
+ mutt_str_strfcpy(old_file, edata->oldpath, sizeof(old_file));
+ old_file[sizeof(old_file) - 1] = '\0';
+ mutt_debug(LL_DEBUG2, "nm: fixing obsolete path '%s'\n", old_file);
}
else
- email_get_fullpath(e, old, sizeof(old));
+ email_get_fullpath(e, old_file, sizeof(old_file));
mutt_buffer_strcpy(m->pathbuf, edata->folder);
m->magic = edata->magic;
break;
if (!e->deleted)
- email_get_fullpath(e, new, sizeof(new));
+ email_get_fullpath(e, new_file, sizeof(new_file));
- if (e->deleted || (strcmp(old, new) != 0))
+ if (e->deleted || (strcmp(old_file, new_file) != 0))
{
- if (e->deleted && (remove_filename(m, old) == 0))
+ if (e->deleted && (remove_filename(m, old_file) == 0))
changed = true;
- else if (*new &&*old && (rename_filename(m, old, new, e) == 0))
+ else if (*new_file && *old_file && (rename_filename(m, old_file, new_file, e) == 0))
changed = true;
}