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, ...@@ -967,7 +967,19 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
967 if (status == 0) 967 if (status == 0)
968 { 968 {
969 if (rename (name, msg_name)) 969 if (rename (name, msg_name))
970 status = errno; 970 {
971 if (errno == ENOENT)
972 mu_observable_notify (amd->mailbox->observable,
973 MU_EVT_MAILBOX_CORRUPT,
974 amd->mailbox);
975 else
976 {
977 status = errno;
978 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
979 ("renaming %s to %s failed: %s",
980 name, msg_name, mu_strerror (status)));
981 }
982 }
971 else 983 else
972 { 984 {
973 mode_t perms; 985 mode_t perms;
...@@ -1372,9 +1384,22 @@ amd_expunge (mu_mailbox_t mailbox) ...@@ -1372,9 +1384,22 @@ amd_expunge (mu_mailbox_t mailbox)
1372 in struct _amd_data indicating that no actual removal 1384 in struct _amd_data indicating that no actual removal
1373 is needed (e.g. for traditional MH). It will allow to 1385 is needed (e.g. for traditional MH). It will allow to
1374 bypass lots of no-op code here. */ 1386 bypass lots of no-op code here. */
1375 if (strcmp (old_name, new_name)) 1387 if (strcmp (old_name, new_name) &&
1376 /* Rename original message */ 1388 /* Rename original message */
1377 rename (old_name, new_name); 1389 rename (old_name, new_name))
1390 {
1391 if (errno == ENOENT)
1392 mu_observable_notify (mailbox->observable,
1393 MU_EVT_MAILBOX_CORRUPT,
1394 mailbox);
1395 else
1396 {
1397 rc = errno;
1398 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
1399 ("renaming %s to %s failed: %s",
1400 old_name, new_name, mu_strerror (rc)));
1401 }
1402 }
1378 } 1403 }
1379 else 1404 else
1380 /* Unlink original file */ 1405 /* Unlink original file */
......
...@@ -789,7 +789,19 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge) ...@@ -789,7 +789,19 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge)
789 return rc; 789 return rc;
790 } 790 }
791 if (rename (cur_name, new_name)) 791 if (rename (cur_name, new_name))
792 rc = errno; 792 {
793 if (errno == ENOENT)
794 mu_observable_notify (amd->mailbox->observable,
795 MU_EVT_MAILBOX_CORRUPT,
796 amd->mailbox);
797 else
798 {
799 rc = errno;
800 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
801 ("renaming %s to %s failed: %s",
802 cur_name, new_name, mu_strerror (rc)));
803 }
804 }
793 free (cur_name); 805 free (cur_name);
794 } 806 }
795 807
......