From: Pierre Habouzit Date: Sat, 18 Nov 2006 16:07:30 +0000 (+0100) Subject: I don't care about systems where atimes are broken. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=bd0ed9bc7c534be30b0140b341b4d8a390483dbd I don't care about systems where atimes are broken. Signed-off-by: Pierre Habouzit --- diff --git a/buffy.c b/buffy.c index 2b77b2d..5fdf725 100644 --- a/buffy.c +++ b/buffy.c @@ -30,127 +30,6 @@ static time_t ImapBuffyTime = 0; /* last time we started checking for mai 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 */ - -static int fseeko_last_message (FILE * f) -{ - LOFF_T pos; - char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ - int bytes_read; - int i; /* Index into `buffer' for scanning. */ - - p_clear(buffer, 1); - fseeko (f, 0, SEEK_END); - pos = ftello (f); - - /* Set `bytes_read' to the size of the last, probably partial, buffer; 0 < - * `bytes_read' <= `BUFSIZ'. */ - bytes_read = pos % BUFSIZ; - if (bytes_read == 0) - bytes_read = BUFSIZ; - /* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all - * reads will be on block boundaries, which might increase efficiency. */ - while ((pos -= bytes_read) >= 0) { - /* we save in the buffer at the end the first 7 chars from the last read */ - strncpy (buffer + BUFSIZ, buffer, 5 + 2); /* 2 == 2 * m_strlen(CRLF) */ - fseeko (f, pos, SEEK_SET); - bytes_read = fread (buffer, sizeof (char), bytes_read, f); - if (bytes_read == -1) - return -1; - for (i = bytes_read; --i >= 0;) - if (!m_strncmp(buffer + i, "\n\nFrom ", m_strlen("\n\nFrom "))) { /* found it - go to the beginning of the From */ - fseeko (f, pos + i + 2, SEEK_SET); - return 0; - } - bytes_read = BUFSIZ; - } - - /* here we are at the beginning of the file */ - if (!m_strncmp("From ", buffer, 5)) { - fseeko (f, 0, 0); - return (0); - } - - return (-1); -} - -/* Return 1 if the last message is new */ -static int test_last_status_new (FILE * f) -{ - HEADER *hdr; - ENVELOPE *tmp_envelope; - int result = 0; - - if (fseeko_last_message (f) == -1) - return (0); - - hdr = header_new(); - tmp_envelope = mutt_read_rfc822_header (f, hdr, 0, 0); - if (!(hdr->read || hdr->old)) - result = 1; - - envelope_delete(&tmp_envelope); - header_delete(&hdr); - - return result; -} - -static int test_new_folder (const char *path) -{ - FILE *f; - int rc = 0; - int typ; - - typ = mx_get_magic (path); - - if (typ != M_MBOX && typ != M_MMDF) - return 0; - - if ((f = fopen (path, "rb"))) { - rc = test_last_status_new (f); - fclose (f); - } - - return rc; -} - -BUFFY *buffy_find_mailbox (const char *path) -{ - struct stat sb; - struct stat tmp_sb; - int i = 0; - - if (stat (path, &sb) != 0) - return NULL; - - if (!list_empty(Incoming)) { - for (i = 0; i < Incoming->length; i++) { - if (stat (Incoming->data[i], &tmp_sb) == 0 && - sb.st_dev == tmp_sb.st_dev && sb.st_ino == tmp_sb.st_ino) - return ((BUFFY*) Incoming->data[i]); - } - } - return (NULL); -} - -void buffy_update_mailbox (BUFFY * b) -{ - struct stat sb; - - if (!b) - return; - - if (stat (b->path, &sb) == 0) - b->size = (long) sb.st_size; - else - b->size = 0; - return; -} -#endif - /* func to free buffy for list_del() */ static inline void buffy_free (BUFFY** p) { p_delete(&(*p)->path); @@ -178,9 +57,6 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, BUFFY* tmp; char buf[_POSIX_PATH_MAX]; int i = 0; -#ifdef BUFFY_SIZE - struct stat sb; -#endif /* BUFFY_SIZE */ while (MoreArgs (s)) { mutt_extract_token (path, s, 0); @@ -219,30 +95,11 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, tmp->notified = 1; tmp->newly_created = 0; -#ifdef BUFFY_SIZE - /* for buffy_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. - */ - if (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. - */ -#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 */ /* values for force: * 0 don't force any checks + update sidebar @@ -302,9 +159,6 @@ int buffy_check (int force) * be ready for when it does. */ tmp->newly_created = 1; tmp->magic = -1; -#ifdef BUFFY_SIZE - tmp->size = 0; -#endif continue; } @@ -323,12 +177,6 @@ int buffy_check (int force) BuffyCount++; tmp->new = 1; } -#ifdef BUFFY_SIZE - else { - /* some other program has deleted mail from the folder */ - tmp->size = (long) sb.st_size; - } -#endif } else if (STAT_CHECK || tmp->msgcount == 0) { /* sidebar visible */ @@ -458,10 +306,6 @@ int buffy_check (int force) } } -#ifdef BUFFY_SIZE - else if (Context && Context->path) - tmp->size = (long) sb.st_size; /* update the size */ -#endif if (tmp->new <= 0) tmp->notified = 0; diff --git a/buffy.h b/buffy.h index 857f594..1e1c55f 100644 --- a/buffy.h +++ b/buffy.h @@ -17,9 +17,6 @@ typedef struct buffy_t { char *path; -#ifdef BUFFY_SIZE - long size; -#endif /* BUFFY_SIZE */ short new; /* mailbox has new mail */ short has_new; /* set it new if new and not read */ int msgcount; /* total number of messages */ @@ -48,9 +45,4 @@ int buffy_list (void); /* wrapper around buffy_list() */ int buffy_notify (void); -#ifdef BUFFY_SIZE -BUFFY *buffy_find_mailbox (const char *path); -void buffy_update_mailbox (BUFFY * b); -#endif - #endif /* !_BUFFY_H */ diff --git a/commands.c b/commands.c index b649356..2be0260 100644 --- a/commands.c +++ b/commands.c @@ -35,10 +35,6 @@ #include -#ifdef BUFFY_SIZE -#include "buffy.h" -#endif - /* The folder the user last saved to. Used by ci_save_message() */ static char LastSaveFolder[_POSIX_PATH_MAX] = ""; @@ -659,12 +655,7 @@ int mutt_save_message (HEADER * h, int delete, 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; @@ -778,20 +769,14 @@ int mutt_save_message (HEADER * h, int delete, mx_close_mailbox (&ctx, NULL); if (need_buffy_cleanup) { -#ifdef BUFFY_SIZE - tmp = buffy_find_mailbox (buf); - if (tmp && tmp->new <= 0) - buffy_update_mailbox (tmp); -#else /* fix up the times so buffy won't get confused */ if (st.st_mtime > st.st_atime) { ut.actime = st.st_atime; ut.modtime = time (NULL); utime (buf, &ut); - } - else + } else { utime (buf, NULL); -#endif + } } mutt_clear_error (); diff --git a/configure.ac b/configure.ac index 4c980b7..5da3b60 100644 --- a/configure.ac +++ b/configure.ac @@ -457,11 +457,6 @@ if test x$ac_cv_dirent_d_ino = xyes ; then fi AC_MSG_RESULT($ac_cv_dirent_d_ino) -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]) - dnl -- start cache -- AC_ARG_ENABLE(hcache, AC_HELP_STRING([--enable-hcache], [Enable header caching]), [if test x$enableval = xyes; then diff --git a/main.c b/main.c index e3778f5..7f5581a 100644 --- a/main.c +++ b/main.c @@ -356,11 +356,6 @@ static void show_version (void) "+CRYPT_BACKEND_GPGME " #else "-CRYPT_BACKEND_GPGME " -#endif -#ifdef BUFFY_SIZE - "+BUFFY_SIZE " -#else - "-BUFFY_SIZE " #endif "\n " #ifdef ENABLE_NLS diff --git a/mbox.c b/mbox.c index 1c10657..3832eee 100644 --- a/mbox.c +++ b/mbox.c @@ -490,7 +490,7 @@ static int mbox_check_mailbox (CONTEXT* ctx, int* index_hint, int lock) { * 0 success * -1 failure */ -static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint) +static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint) { char tempfile[_POSIX_PATH_MAX]; char buf[32]; @@ -806,19 +806,6 @@ bail: /* Come here in case of disaster */ return rc; } -static int mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { -#ifdef BUFFY_SIZE - BUFFY* tmp = NULL; -#endif - int rc = _mbox_sync_mailbox (ctx, unused, index_hint); - -#ifdef BUFFY_SIZE - if ((tmp = buffy_find_mailbox (ctx->path)) && tmp->new == 0) - buffy_update_mailbox (tmp); -#endif - return (rc); -} - /* close a mailbox opened in write-mode */ int mbox_close_mailbox (CONTEXT * ctx) { @@ -1023,16 +1010,15 @@ int mbox_is_magic (const char* path, struct stat* st) { return (M_MBOX); } else if ((f = fopen (path, "r")) != NULL) { -#ifndef BUFFY_SIZE struct utimbuf times; -#endif + fgets (tmp, sizeof (tmp), f); if (m_strncmp("From ", tmp, 5) == 0) magic = M_MBOX; else if (m_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. @@ -1040,7 +1026,6 @@ int mbox_is_magic (const char* path, struct stat* st) { times.actime = st->st_atime; times.modtime = st->st_mtime; utime (path, ×); -#endif } else { mutt_perror (path); return (-1); /* fopen failed */