Commit f5703c26 f5703c2608a90cb12b39a8194c6257f91fc09d65 by Sergey Poznyakoff

amd: report MU_EVT_MAILBOX_CORRUPT if unable to rename message file due to ENOENT

* libmailutils/base/amd.c
* libproto/maildir/mbox.c
1 parent fa3be4ba
......@@ -967,7 +967,19 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
if (status == 0)
{
if (rename (name, msg_name))
status = errno;
{
if (errno == ENOENT)
mu_observable_notify (amd->mailbox->observable,
MU_EVT_MAILBOX_CORRUPT,
amd->mailbox);
else
{
status = errno;
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
("renaming %s to %s failed: %s",
name, msg_name, mu_strerror (status)));
}
}
else
{
mode_t perms;
......@@ -1372,9 +1384,22 @@ amd_expunge (mu_mailbox_t mailbox)
in struct _amd_data indicating that no actual removal
is needed (e.g. for traditional MH). It will allow to
bypass lots of no-op code here. */
if (strcmp (old_name, new_name))
/* Rename original message */
rename (old_name, new_name);
if (strcmp (old_name, new_name) &&
/* Rename original message */
rename (old_name, new_name))
{
if (errno == ENOENT)
mu_observable_notify (mailbox->observable,
MU_EVT_MAILBOX_CORRUPT,
mailbox);
else
{
rc = errno;
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
("renaming %s to %s failed: %s",
old_name, new_name, mu_strerror (rc)));
}
}
}
else
/* Unlink original file */
......
......@@ -789,7 +789,19 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge)
return rc;
}
if (rename (cur_name, new_name))
rc = errno;
{
if (errno == ENOENT)
mu_observable_notify (amd->mailbox->observable,
MU_EVT_MAILBOX_CORRUPT,
amd->mailbox);
else
{
rc = errno;
mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
("renaming %s to %s failed: %s",
cur_name, new_name, mu_strerror (rc)));
}
}
free (cur_name);
}
......