Re: [PATCH] runtime configurable buffy size
On Wed, Feb 28, 2007 at 02:33:17PM +0100, Christoph Berg wrote:
> Re: Miroslav Lichvar 2007-02-28 <20070228130731.GA23284@localhost>
> > attached is a patch that makes the buffy size option configurable at
> > runtime. Mutt binary compiled with --enable-buffy-size will
> > have an extra boolean variable that controls if mbox size should be
> > used when checking for new mail.
>
> > +++ init.h 28 Feb 2007 12:38:11 -0000
> > +#ifdef BUFFY_SIZE
> > + { "buffy_size", DT_BOOL, R_NONE, OPTBUFFYSIZE, 1 },
>
> I'd remove the ./configure option and let it default to 0.
>
> This would also be the chance to give the option a less silly name,
> e.g. check_mbox_size.
Ok, here is a patch that removes buffy_size completely and adds the
check_box_size option.
--
Miroslav Lichvar
Index: buffy.c
===================================================================
RCS file: /home/roessler/cvs/mutt/buffy.c,v
retrieving revision 3.20
diff -u -r3.20 buffy.c
--- buffy.c 19 Nov 2006 05:19:09 -0000 3.20
+++ buffy.c 1 Mar 2007 14:52:15 -0000
@@ -45,8 +45,6 @@
static short BuffyCount = 0; /* how many boxes with new mail */
static short BuffyNotify = 0; /* # of unnotified new boxes */
-#ifdef BUFFY_SIZE
-
/* Find the last message in the file.
* upon success return 0. If no message found - return -1 */
@@ -142,7 +140,7 @@
struct stat sb;
struct stat tmp_sb;
- if (stat (path,&sb) != 0)
+ if (!option(OPTCHECKMBOXSIZE) || stat (path,&sb) != 0)
return NULL;
for (tmp = Incoming; tmp; tmp = tmp->next)
@@ -167,15 +165,12 @@
b->size = 0;
return;
}
-#endif
int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER
*err)
{
BUFFY **tmp,*tmp1;
char buf[_POSIX_PATH_MAX];
-#ifdef BUFFY_SIZE
struct stat sb;
-#endif /* BUFFY_SIZE */
while (MoreArgs (s))
{
@@ -232,31 +227,28 @@
(*tmp)->notified = 1;
(*tmp)->newly_created = 0;
-#ifdef BUFFY_SIZE
- /* for buffy_size, it is important that if the folder is new (tested by
+ /* for check_mbox_size, it is important that if the folder is new (tested
by
* reading it), the size is set to 0 so that later when we check we see
- * that it increased . without buffy_size we probably don't care.
+ * that it increased . without check_mbox_size we probably don't care.
*/
- if (stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path))
+ if (option(OPTCHECKMBOXSIZE) &&
+ stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path))
{
/* some systems out there don't have an off_t type */
(*tmp)->size = (long) sb.st_size;
}
else
(*tmp)->size = 0;
-#endif /* BUFFY_SIZE */
}
return 0;
}
-#ifdef BUFFY_SIZE
-/* people use buffy_size on systems where modified time attributes are BADLY
- * broken. Ignore them.
+/* people use check_mbox_size on systems where modified time attributes are
+ * BADLY broken. Ignore them.
*/
-#define STAT_CHECK (sb.st_size > tmp->size)
-#else
-#define STAT_CHECK (sb.st_mtime > sb.st_atime || (tmp->newly_created &&
sb.st_ctime == sb.st_mtime && sb.st_ctime == sb.st_atime))
-#endif /* BUFFY_SIZE */
+#define STAT_CHECK_SIZE (sb.st_size > tmp->size)
+#define STAT_CHECK_TIME (sb.st_mtime > sb.st_atime || (tmp->newly_created &&
sb.st_ctime == sb.st_mtime && sb.st_ctime == sb.st_atime))
+#define STAT_CHECK (option(OPTCHECKMBOXSIZE) ? STAT_CHECK_SIZE :
STAT_CHECK_TIME)
int mutt_buffy_check (int force)
{
@@ -323,9 +315,7 @@
* be ready for when it does. */
tmp->newly_created = 1;
tmp->magic = 0;
-#ifdef BUFFY_SIZE
tmp->size = 0;
-#endif
continue;
}
#ifdef USE_IMAP
@@ -365,13 +355,11 @@
BuffyCount++;
tmp->new = 1;
}
-#ifdef BUFFY_SIZE
else
{
/* some other program has deleted mail from the folder */
tmp->size = (long) sb.st_size;
}
-#endif
if (tmp->newly_created &&
(sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
tmp->newly_created = 0;
@@ -407,10 +395,8 @@
break;
}
}
-#ifdef BUFFY_SIZE
else if (Context && Context->path)
tmp->size = (long) sb.st_size; /* update the size */
-#endif
if (!tmp->new)
tmp->notified = 0;
Index: buffy.h
===================================================================
RCS file: /home/roessler/cvs/mutt/buffy.h,v
retrieving revision 3.4
diff -u -r3.4 buffy.h
--- buffy.h 17 Sep 2005 20:46:10 -0000 3.4
+++ buffy.h 1 Mar 2007 14:52:15 -0000
@@ -23,9 +23,7 @@
typedef struct buffy_t
{
char *path;
-#ifdef BUFFY_SIZE
long size;
-#endif /* BUFFY_SIZE */
struct buffy_t *next;
short new; /* mailbox has new mail */
short notified; /* user has been notified */
@@ -39,7 +37,5 @@
extern time_t BuffyDoneTime; /* last time we knew for sure how much mail
there was */
-#ifdef BUFFY_SIZE
BUFFY *mutt_find_mailbox (const char *path);
void mutt_update_mailbox (BUFFY * b);
-#endif
Index: commands.c
===================================================================
RCS file: /home/roessler/cvs/mutt/commands.c,v
retrieving revision 3.37
diff -u -r3.37 commands.c
--- commands.c 7 Dec 2006 11:34:34 -0000 3.37
+++ commands.c 1 Mar 2007 14:52:15 -0000
@@ -40,9 +40,7 @@
#include "imap.h"
#endif
-#ifdef BUFFY_SIZE
#include "buffy.h"
-#endif
#include <errno.h>
#include <unistd.h>
@@ -703,11 +701,8 @@
char prompt[SHORT_STRING], buf[_POSIX_PATH_MAX];
CONTEXT ctx;
struct stat st;
-#ifdef BUFFY_SIZE
BUFFY *tmp = NULL;
-#else
struct utimbuf ut;
-#endif
*redraw = 0;
@@ -842,11 +837,9 @@
if (need_buffy_cleanup)
{
-#ifdef BUFFY_SIZE
tmp = mutt_find_mailbox (buf);
if (tmp && !tmp->new)
mutt_update_mailbox (tmp);
-#else
/* fix up the times so buffy won't get confused */
if (st.st_mtime > st.st_atime)
{
@@ -856,7 +849,6 @@
}
else
utime (buf, NULL);
-#endif
}
mutt_clear_error ();
Index: configure.in
===================================================================
RCS file: /home/roessler/cvs/mutt/configure.in,v
retrieving revision 3.58
diff -u -r3.58 configure.in
--- configure.in 24 Feb 2007 06:37:31 -0000 3.58
+++ configure.in 1 Mar 2007 14:52:15 -0000
@@ -793,11 +793,6 @@
incorrectly cache the attributes of small files.])
fi])
-AC_ARG_ENABLE(buffy-size, AC_HELP_STRING([--enable-buffy-size], [Use file size
attribute instead of access time]),
- [if test x$enableval = xyes; then
- AC_DEFINE(BUFFY_SIZE,1,[ Define to enable the "buffy_size"
feature. ])
- fi])
-
AC_ARG_ENABLE(mailtool, AC_HELP_STRING([--enable-mailtool], [Enable Sun
mailtool attachments support]),
[if test x$enableval = xyes; then
AC_DEFINE(SUN_ATTACHMENT,1,[ Define to enable Sun mailtool
attachments support. ])
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.111
diff -u -r3.111 init.h
--- init.h 1 Mar 2007 06:05:39 -0000 3.111
+++ init.h 1 Mar 2007 14:52:15 -0000
@@ -351,6 +351,12 @@
** follow these menus. The option is disabled by default because many
** visual terminals don't permit making the cursor invisible.
*/
+ { "check_mbox_size", DT_BOOL, R_NONE, OPTCHECKMBOXSIZE, 0 },
+ /*
+ ** .pp
+ ** When this variable is set, mutt will use file size attribute instead of
+ ** access time when checking for new mail.
+ */
{ "charset", DT_STR, R_NONE, UL &Charset, UL 0 },
/*
** .pp
Index: main.c
===================================================================
RCS file: /home/roessler/cvs/mutt/main.c,v
retrieving revision 3.39
diff -u -r3.39 main.c
--- main.c 26 Feb 2007 17:27:29 -0000 3.39
+++ main.c 1 Mar 2007 14:52:15 -0000
@@ -374,11 +374,6 @@
);
puts (
-#ifdef BUFFY_SIZE
- "+BUFFY_SIZE "
-#else
- "-BUFFY_SIZE "
-#endif
#ifdef EXACT_ADDRESS
"+EXACT_ADDRESS "
#else
Index: mutt.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt.h,v
retrieving revision 3.72
diff -u -r3.72 mutt.h
--- mutt.h 27 Feb 2007 17:44:09 -0000 3.72
+++ mutt.h 1 Mar 2007 14:52:15 -0000
@@ -338,6 +338,7 @@
OPTBEEPNEW,
OPTBOUNCEDELIVERED,
OPTBRAILLEFRIENDLY,
+ OPTCHECKMBOXSIZE,
OPTCHECKNEW,
OPTCOLLAPSEUNREAD,
OPTCONFIRMAPPEND,
Index: mx.c
===================================================================
RCS file: /home/roessler/cvs/mutt/mx.c,v
retrieving revision 3.27
diff -u -r3.27 mx.c
--- mx.c 15 Aug 2006 17:08:32 -0000 3.27
+++ mx.c 1 Mar 2007 14:52:15 -0000
@@ -38,9 +38,7 @@
#include "pop.h"
#endif
-#ifdef BUFFY_SIZE
#include "buffy.h"
-#endif
#ifdef USE_DOTLOCK
#include "dotlock.h"
@@ -57,9 +55,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#ifndef BUFFY_SIZE
#include <utime.h>
-#endif
#define mutt_is_spool(s) (mutt_strcmp (Spoolfile, s) == 0)
@@ -426,9 +422,7 @@
}
else if ((f = fopen (path, "r")) != NULL)
{
-#ifndef BUFFY_SIZE
struct utimbuf times;
-#endif
fgets (tmp, sizeof (tmp), f);
if (mutt_strncmp ("From ", tmp, 5) == 0)
@@ -436,7 +430,7 @@
else if (mutt_strcmp (MMDF_SEP, tmp) == 0)
magic = M_MMDF;
safe_fclose (&f);
-#ifndef BUFFY_SIZE
+
/* need to restore the times here, the file was not really accessed,
* only the type was accessed. This is important, because detection
* of "new mail" depends on those times set correctly.
@@ -444,7 +438,6 @@
times.actime = st.st_atime;
times.modtime = st.st_mtime;
utime (path, ×);
-#endif
}
else
{
@@ -773,9 +766,7 @@
/* save changes to disk */
static int sync_mailbox (CONTEXT *ctx, int *index_hint)
{
-#ifdef BUFFY_SIZE
BUFFY *tmp = NULL;
-#endif
int rc = -1;
if (!ctx->quiet)
@@ -786,9 +777,7 @@
case M_MBOX:
case M_MMDF:
rc = mbox_sync_mailbox (ctx, index_hint);
-#ifdef BUFFY_SIZE
tmp = mutt_find_mailbox (ctx->path);
-#endif
break;
case M_MH:
@@ -815,10 +804,8 @@
mutt_error ( _("Could not synchronize mailbox %s!"), ctx->path);
#endif
-#ifdef BUFFY_SIZE
if (tmp && tmp->new == 0)
mutt_update_mailbox (tmp);
-#endif
return rc;
}