mutt stable branch with some hacks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Convert mbox_sync_mailbox() to use buffer pool.

Rewrite return(-1) to a new fatal target to ensure cleanup.

Remove some repetitive unlink(tempfile) operations by adding a new
flag pointing when to start and stop that during a bail.

+38 -34
+38 -34
mbox.c
··· 833 833 */ 834 834 static int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) 835 835 { 836 - char tempfile[_POSIX_PATH_MAX]; 836 + BUFFER *tempfile = NULL; 837 837 char buf[32]; 838 838 int i, j, save_sort = SORT_ORDER; 839 + int unlink_tempfile = 0; 839 840 int rc = -1; 840 841 int need_sort = 0; /* flag to resort mailbox if new mail arrives */ 841 842 int first = -1; /* first message to be written */ ··· 865 866 { 866 867 mx_fastclose_mailbox (ctx); 867 868 mutt_error _("Fatal error! Could not reopen mailbox!"); 868 - return (-1); 869 + goto fatal; 869 870 } 870 871 871 872 mutt_block_signals (); ··· 885 886 goto bail; 886 887 } 887 888 else if (i < 0) 888 - /* fatal error */ 889 - return (-1); 889 + goto fatal; 890 890 891 891 /* Create a temporary file to write the new version of the mailbox in. */ 892 - mutt_mktemp (tempfile, sizeof (tempfile)); 893 - if ((i = open (tempfile, O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1 || 892 + tempfile = mutt_buffer_pool_get (); 893 + mutt_buffer_mktemp (tempfile); 894 + if ((i = open (mutt_b2s (tempfile), O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1 || 894 895 (fp = fdopen (i, "w")) == NULL) 895 896 { 896 897 if (-1 != i) 897 898 { 898 899 close (i); 899 - unlink (tempfile); 900 + unlink_tempfile = 1; 900 901 } 901 902 mutt_error _("Could not create temporary file!"); 902 903 mutt_sleep (5); 903 904 goto bail; 904 905 } 906 + unlink_tempfile = 1; 905 907 906 908 /* find the first deleted/changed message. we save a lot of time by only 907 909 * rewriting the mailbox from the point where it has actually changed. ··· 918 920 mutt_error _("sync: mbox modified, but no modified messages! (report this bug)"); 919 921 mutt_sleep(5); /* the mutt_error /will/ get cleared! */ 920 922 dprint(1, (debugfile, "mbox_sync_mailbox(): no modified messages.\n")); 921 - unlink (tempfile); 922 923 goto bail; 923 924 } 924 925 ··· 966 967 { 967 968 if (fputs (MMDF_SEP, fp) == EOF) 968 969 { 969 - mutt_perror (tempfile); 970 + mutt_perror (mutt_b2s (tempfile)); 970 971 mutt_sleep (5); 971 - unlink (tempfile); 972 972 goto bail; 973 973 } 974 974 ··· 983 983 if (mutt_copy_message (fp, ctx, ctx->hdrs[i], MUTT_CM_UPDATE, 984 984 CH_FROM | CH_UPDATE | CH_UPDATE_LEN) != 0) 985 985 { 986 - mutt_perror (tempfile); 986 + mutt_perror (mutt_b2s (tempfile)); 987 987 mutt_sleep (5); 988 - unlink (tempfile); 989 988 goto bail; 990 989 } 991 990 ··· 1003 1002 case MUTT_MMDF: 1004 1003 if (fputs(MMDF_SEP, fp) == EOF) 1005 1004 { 1006 - mutt_perror (tempfile); 1005 + mutt_perror (mutt_b2s (tempfile)); 1007 1006 mutt_sleep (5); 1008 - unlink (tempfile); 1009 1007 goto bail; 1010 1008 } 1011 1009 break; 1012 1010 default: 1013 1011 if (fputs("\n", fp) == EOF) 1014 1012 { 1015 - mutt_perror (tempfile); 1013 + mutt_perror (mutt_b2s (tempfile)); 1016 1014 mutt_sleep (5); 1017 - unlink (tempfile); 1018 1015 goto bail; 1019 1016 } 1020 1017 } ··· 1025 1022 { 1026 1023 fp = NULL; 1027 1024 dprint(1, (debugfile, "mbox_sync_mailbox: safe_fclose (&) returned non-zero.\n")); 1028 - unlink (tempfile); 1029 - mutt_perror (tempfile); 1025 + mutt_perror (mutt_b2s (tempfile)); 1030 1026 mutt_sleep (5); 1031 1027 goto bail; 1032 1028 } ··· 1037 1033 { 1038 1034 mutt_perror (ctx->path); 1039 1035 mutt_sleep (5); 1040 - unlink (tempfile); 1041 1036 goto bail; 1042 1037 } 1043 1038 1044 - if ((fp = fopen (tempfile, "r")) == NULL) 1039 + unlink_tempfile = 0; 1040 + 1041 + if ((fp = fopen (mutt_b2s (tempfile), "r")) == NULL) 1045 1042 { 1046 1043 mutt_unblock_signals (); 1047 1044 mx_fastclose_mailbox (ctx); 1048 1045 dprint (1, (debugfile, "mbox_sync_mailbox: unable to reopen temp copy of mailbox!\n")); 1049 - mutt_perror (tempfile); 1046 + mutt_perror (mutt_b2s (tempfile)); 1050 1047 mutt_sleep (5); 1051 - return (-1); 1048 + goto fatal; 1052 1049 } 1053 1050 1054 1051 if (fseeko (ctx->fp, offset, SEEK_SET) != 0 || /* seek the append location */ ··· 1097 1094 1098 1095 if (safe_fclose (&ctx->fp) != 0 || i == -1) 1099 1096 { 1097 + BUFFER *savefile; 1100 1098 /* error occurred while writing the mailbox back, so keep the temp copy 1101 1099 * around 1102 1100 */ 1103 - 1104 - char savefile[_POSIX_PATH_MAX]; 1105 - 1106 - snprintf (savefile, sizeof (savefile), "%s/mutt.%s-%s-%u", 1101 + savefile = mutt_buffer_pool_get (); 1102 + mutt_buffer_printf (savefile, "%s/mutt.%s-%s-%u", 1107 1103 NONULL (Tempdir), NONULL(Username), NONULL(Hostname), (unsigned int)getpid ()); 1108 - rename (tempfile, savefile); 1104 + rename (mutt_b2s (tempfile), mutt_b2s (savefile)); 1109 1105 mutt_unblock_signals (); 1110 1106 mx_fastclose_mailbox (ctx); 1111 - mutt_pretty_mailbox (savefile, sizeof (savefile)); 1112 - mutt_error (_("Write failed! Saved partial mailbox to %s"), savefile); 1107 + mutt_buffer_pretty_mailbox (savefile); 1108 + mutt_error (_("Write failed! Saved partial mailbox to %s"), mutt_b2s (savefile)); 1109 + mutt_buffer_pool_release (&savefile); 1110 + 1113 1111 mutt_sleep (5); 1114 - return (-1); 1112 + goto fatal; 1115 1113 } 1116 1114 1117 1115 /* Restore the previous access/modification times */ ··· 1120 1118 /* reopen the mailbox in read-only mode */ 1121 1119 if ((ctx->fp = fopen (ctx->path, "r")) == NULL) 1122 1120 { 1123 - unlink (tempfile); 1121 + unlink (mutt_b2s (tempfile)); 1124 1122 mutt_unblock_signals (); 1125 1123 mx_fastclose_mailbox (ctx); 1126 1124 mutt_error _("Fatal error! Could not reopen mailbox!"); 1127 - return (-1); 1125 + goto fatal; 1128 1126 } 1129 1127 1130 1128 /* update the offsets of the rewritten messages */ ··· 1140 1138 } 1141 1139 FREE (&newOffset); 1142 1140 FREE (&oldOffset); 1143 - unlink (tempfile); /* remove partial copy of the mailbox */ 1141 + unlink (mutt_b2s (tempfile)); /* remove partial copy of the mailbox */ 1142 + mutt_buffer_pool_release (&tempfile); 1144 1143 mutt_unblock_signals (); 1145 1144 1146 1145 if (option(OPTCHECKMBOXSIZE)) ··· 1155 1154 bail: /* Come here in case of disaster */ 1156 1155 1157 1156 safe_fclose (&fp); 1157 + 1158 + if (tempfile && unlink_tempfile) 1159 + unlink (mutt_b2s (tempfile)); 1158 1160 1159 1161 /* restore offsets, as far as they are valid */ 1160 1162 if (first >= 0 && oldOffset) ··· 1180 1182 { 1181 1183 mutt_error _("Could not reopen mailbox!"); 1182 1184 mx_fastclose_mailbox (ctx); 1183 - return (-1); 1185 + goto fatal; 1184 1186 } 1185 1187 1186 1188 if (need_sort) ··· 1188 1190 * sure to start threading from scratch. */ 1189 1191 mutt_sort_headers (ctx, (need_sort == MUTT_REOPENED)); 1190 1192 1193 + fatal: 1194 + mutt_buffer_pool_release (&tempfile); 1191 1195 return rc; 1192 1196 } 1193 1197