Commit 751aad90 751aad904e7d642240de2106de95429f8c248ea7 by Sergey Poznyakoff

Improve diagnostics in maildir

* libmailutils/mailbox/fsfolder.c: Fix debugging categories
* libproto/maildir/mbox.c (maildir_opendir)
(maildir_msg_finish_delivery)
(maildir_scan0): Log errors.
(maildir_flush,maildir_deliver_new): Return EACCES if the mailbox is read-only.
1 parent 89d93a75
...@@ -222,7 +222,7 @@ list_helper (struct search_data *data, mu_record_t record, ...@@ -222,7 +222,7 @@ list_helper (struct search_data *data, mu_record_t record,
222 dirp = opendir (dirname); 222 dirp = opendir (dirname);
223 if (dirp == NULL) 223 if (dirp == NULL)
224 { 224 {
225 mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR, 225 mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
226 ("list_helper cannot open directory %s: %s", 226 ("list_helper cannot open directory %s: %s",
227 dirname, mu_strerror (errno))); 227 dirname, mu_strerror (errno)));
228 data->errcnt++; 228 data->errcnt++;
...@@ -276,7 +276,7 @@ list_helper (struct search_data *data, mu_record_t record, ...@@ -276,7 +276,7 @@ list_helper (struct search_data *data, mu_record_t record,
276 resp = malloc (sizeof (*resp)); 276 resp = malloc (sizeof (*resp));
277 if (resp == NULL) 277 if (resp == NULL)
278 { 278 {
279 mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR, 279 mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
280 ("list_helper: %s", mu_strerror (ENOMEM))); 280 ("list_helper: %s", mu_strerror (ENOMEM)));
281 data->errcnt++; 281 data->errcnt++;
282 free (fname); 282 free (fname);
...@@ -343,7 +343,7 @@ list_helper (struct search_data *data, mu_record_t record, ...@@ -343,7 +343,7 @@ list_helper (struct search_data *data, mu_record_t record,
343 } 343 }
344 else 344 else
345 { 345 {
346 mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_ERROR, 346 mu_debug (MU_DEBCAT_FOLDER, MU_DEBUG_ERROR,
347 ("list_helper cannot stat %s: %s", 347 ("list_helper cannot stat %s: %s",
348 fname, mu_strerror (errno))); 348 fname, mu_strerror (errno)));
349 } 349 }
......
...@@ -390,7 +390,7 @@ maildir_delete_file (char *dirname, char *filename) ...@@ -390,7 +390,7 @@ maildir_delete_file (char *dirname, char *filename)
390 struct stat st; 390 struct stat st;
391 char *name; 391 char *name;
392 int rc; 392 int rc;
393 393
394 rc = maildir_mkfilename (dirname, filename, NULL, &name); 394 rc = maildir_mkfilename (dirname, filename, NULL, &name);
395 if (rc) 395 if (rc)
396 { 396 {
...@@ -412,21 +412,32 @@ maildir_delete_file (char *dirname, char *filename) ...@@ -412,21 +412,32 @@ maildir_delete_file (char *dirname, char *filename)
412 static int 412 static int
413 maildir_opendir (DIR **dir, char *name, int permissions) 413 maildir_opendir (DIR **dir, char *name, int permissions)
414 { 414 {
415 int rc = 0;
416
415 *dir = opendir (name); 417 *dir = opendir (name);
416 if (!*dir) 418 if (!*dir)
417 { 419 {
418 if (errno == ENOENT) 420 if (errno == ENOENT)
419 { 421 {
420 if (mkdir (name, permissions)) 422 if (mkdir (name, permissions))
421 return errno; 423 {
424 rc = errno;
425 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
426 ("can't create directory %s: %s",
427 name, mu_strerror (rc)));
428 return rc;
429 }
430
422 *dir = opendir (name); 431 *dir = opendir (name);
423 if (!*dir) 432 if (*dir)
424 return errno; 433 return 0;
425 } 434 }
426 else 435 rc = errno;
427 return errno; 436 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
437 ("can't open directory %s: %s",
438 name, mu_strerror (rc)));
428 } 439 }
429 return 0; 440 return rc;
430 } 441 }
431 442
432 static int 443 static int
...@@ -529,11 +540,28 @@ maildir_msg_finish_delivery (struct _amd_data *amd, struct _amd_message *amm, ...@@ -529,11 +540,28 @@ maildir_msg_finish_delivery (struct _amd_data *amd, struct _amd_message *amm,
529 540
530 if (rc == 0) 541 if (rc == 0)
531 { 542 {
532 unlink (newname); 543 if (unlink (newname))
533 if (link (oldname, newname) == 0) 544 {
534 unlink (oldname); 545 rc = errno;
546 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
547 ("can't unlink %s: %s",
548 newname, mu_strerror (errno)));
549 }
550 else if (link (oldname, newname) == 0)
551 {
552 if (unlink (oldname))
553 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
554 ("can't unlink %s: %s",
555 oldname, mu_strerror (errno)));
556 }
535 else 557 else
536 rc = errno; /* FIXME? */ 558 {
559 rc = errno;
560 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
561 ("renaming %s to %s failed: %s",
562 oldname, newname, mu_strerror (rc)));
563 }
564
537 } 565 }
538 566
539 free (oldname); 567 free (oldname);
...@@ -552,6 +580,9 @@ maildir_flush (struct _amd_data *amd) ...@@ -552,6 +580,9 @@ maildir_flush (struct _amd_data *amd)
552 struct dirent *entry; 580 struct dirent *entry;
553 char *tmpname; 581 char *tmpname;
554 582
583 if (!(amd->mailbox->flags & MU_STREAM_WRITE))
584 return EACCES;
585
555 rc = maildir_mkfilename (amd->name, TMPSUF, NULL, &tmpname); 586 rc = maildir_mkfilename (amd->name, TMPSUF, NULL, &tmpname);
556 if (rc) 587 if (rc)
557 return rc; 588 return rc;
...@@ -588,7 +619,10 @@ int ...@@ -588,7 +619,10 @@ int
588 maildir_deliver_new (struct _amd_data *amd, DIR *dir) 619 maildir_deliver_new (struct _amd_data *amd, DIR *dir)
589 { 620 {
590 struct dirent *entry; 621 struct dirent *entry;
622 int err = 0;
591 623
624 if (!(amd->mailbox->flags & MU_STREAM_WRITE))
625 return EACCES;
592 while ((entry = readdir (dir))) 626 while ((entry = readdir (dir)))
593 { 627 {
594 char *oldname, *newname; 628 char *oldname, *newname;
...@@ -609,12 +643,18 @@ maildir_deliver_new (struct _amd_data *amd, DIR *dir) ...@@ -609,12 +643,18 @@ maildir_deliver_new (struct _amd_data *amd, DIR *dir)
609 free (oldname); 643 free (oldname);
610 return rc; 644 return rc;
611 } 645 }
612 rename (oldname, newname); /* FIXME: Error code? */ 646 if (rename (oldname, newname))
647 {
648 err = MU_ERR_FAILURE;
649 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
650 ("renaming %s to %s failed: %s",
651 oldname, newname, mu_strerror (errno)));
652 }
613 free (oldname); 653 free (oldname);
614 free (newname); 654 free (newname);
615 } 655 }
616 } 656 }
617 return 0; 657 return err;
618 } 658 }
619 659
620 static int 660 static int
...@@ -635,8 +675,8 @@ maildir_scan_dir (struct _amd_data *amd, DIR *dir, char *dirname) ...@@ -635,8 +675,8 @@ maildir_scan_dir (struct _amd_data *amd, DIR *dir, char *dirname)
635 break; 675 break;
636 676
637 default: 677 default:
638 /* Message not found. Index pointd to the array cell where it 678 /* Message not found. Index points to the array cell where it
639 would be placed */ 679 would be placed */
640 msg = calloc (1, sizeof (*msg)); 680 msg = calloc (1, sizeof (*msg));
641 if (!msg) 681 if (!msg)
642 { 682 {
...@@ -702,9 +742,7 @@ maildir_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED, ...@@ -702,9 +742,7 @@ maildir_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED,
702 mu_stream_flags_to_mode (mailbox->flags, 1)); 742 mu_stream_flags_to_mode (mailbox->flags, 1));
703 if (status == 0) 743 if (status == 0)
704 { 744 {
705 if (mailbox->flags & MU_STREAM_WRITE) 745 if (maildir_deliver_new (amd, dir))
706 maildir_deliver_new (amd, dir);
707 else
708 status = maildir_scan_dir (amd, dir, NEWSUF); 746 status = maildir_scan_dir (amd, dir, NEWSUF);
709 closedir (dir); 747 closedir (dir);
710 } 748 }
...@@ -824,7 +862,12 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge) ...@@ -824,7 +862,12 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge)
824 if (!new_name) 862 if (!new_name)
825 { 863 {
826 if (unlink (mp->file_name)) 864 if (unlink (mp->file_name))
827 rc = errno; 865 {
866 rc = errno;
867 mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
868 ("can't unlink %s: %s",
869 mp->file_name, mu_strerror (rc)));
870 }
828 } 871 }
829 else 872 else
830 { 873 {
......