~ubuntu-branches/ubuntu/precise/mutt/precise

« back to all changes in this revision

Viewing changes to debian/patches/upstream/533439-mbox-time.patch

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-27 23:52:24 UTC
  • mfrom: (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090627235224-z52j0hm6cpknxrk1
Tags: 1.5.20-2ubuntu1
Merge from debian unstable (LP: #392997), remaining changes:
debian/control: Recommend default-mta instead of exim4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
upstream test patch to fix the atime issue
 
2
(See #533439 and upstream #3271, #1372)
 
3
 
 
4
--- a/mbox.c
 
5
+++ b/mbox.c
 
6
@@ -685,22 +685,30 @@
 
7
 
 
8
 /* if mailbox has at least 1 new message, sets mtime > atime of mailbox
 
9
  * so buffy check reports new mail */
 
10
-static void reset_atime (CONTEXT *ctx)
 
11
+void mbox_reset_atime (CONTEXT *ctx, struct stat *st)
 
12
 {
 
13
   struct utimbuf utimebuf;
 
14
-  int i;
 
15
-  time_t now = time (NULL);
 
16
+  int i, found = 0;
 
17
+  struct stat _st;
 
18
 
 
19
-  for (i = 0; i < ctx->msgcount; i++)
 
20
+  if (!st)
 
21
   {
 
22
-    if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
 
23
-    {
 
24
-      utimebuf.actime = now - 1;
 
25
-      utimebuf.modtime = now;
 
26
-      utime (ctx->path, &utimebuf);
 
27
+    if (stat (ctx->path, &_st) < 0)
 
28
       return;
 
29
-    }
 
30
+    st = &_st;
 
31
   }
 
32
+
 
33
+  utimebuf.actime = st->st_atime;
 
34
+  utimebuf.modtime = st->st_mtime;
 
35
+
 
36
+  for (i = 0; !found && i < ctx->msgcount; i++)
 
37
+    if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
 
38
+      found = 1;
 
39
+
 
40
+  if (found && utimebuf.actime >= utimebuf.modtime)
 
41
+    utimebuf.actime = utimebuf.modtime - 1;
 
42
+
 
43
+  utime (ctx->path, &utimebuf);
 
44
 }
 
45
 
 
46
 /* return values:
 
47
@@ -716,6 +724,7 @@
 
48
   int need_sort = 0; /* flag to resort mailbox if new mail arrives */
 
49
   int first = -1;      /* first message to be written */
 
50
   LOFF_T offset;       /* location in mailbox to write changed messages */
 
51
+  struct stat statbuf;
 
52
   struct m_update_t *newOffset = NULL;
 
53
   struct m_update_t *oldOffset = NULL;
 
54
   FILE *fp = NULL;
 
55
@@ -907,6 +916,15 @@
 
56
   }
 
57
   fp = NULL;
 
58
 
 
59
+  /* Save the state of this folder. */
 
60
+  if (stat (ctx->path, &statbuf) == -1)
 
61
+  {
 
62
+    mutt_perror (ctx->path);
 
63
+    mutt_sleep (5);
 
64
+    unlink (tempfile);
 
65
+    goto bail;
 
66
+  }
 
67
+
 
68
   if ((fp = fopen (tempfile, "r")) == NULL)
 
69
   {
 
70
     mutt_unblock_signals ();
 
71
@@ -976,6 +994,9 @@
 
72
     return (-1);
 
73
   }
 
74
 
 
75
+  /* Restore the previous access/modification times */
 
76
+  mbox_reset_atime (ctx, &statbuf);
 
77
+
 
78
   /* reopen the mailbox in read-only mode */
 
79
   if ((ctx->fp = fopen (ctx->path, "r")) == NULL)
 
80
   {
 
81
@@ -1002,11 +1023,6 @@
 
82
   unlink (tempfile); /* remove partial copy of the mailbox */
 
83
   mutt_unblock_signals ();
 
84
 
 
85
-  /* if mailbox has new mail, mangle atime+mtime to make buffy check
 
86
-   * report new mail for it */
 
87
-  if (!option (OPTCHECKMBOXSIZE))
 
88
-    reset_atime (ctx);
 
89
-
 
90
   return (0); /* signal success */
 
91
 
 
92
 bail:  /* Come here in case of disaster */
 
93
--- a/mx.c
 
94
+++ b/mx.c
 
95
@@ -1005,6 +1005,8 @@
 
96
   {
 
97
     if (!ctx->quiet)
 
98
       mutt_message _("Mailbox is unchanged.");
 
99
+    if (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
 
100
+      mbox_reset_atime (ctx, NULL);
 
101
     mx_fastclose_mailbox (ctx);
 
102
     return 0;
 
103
   }
 
104
--- a/mx.h
 
105
+++ b/mx.h
 
106
@@ -59,6 +59,7 @@
 
107
 int mmdf_parse_mailbox (CONTEXT *);
 
108
 void mbox_unlock_mailbox (CONTEXT *);
 
109
 int mbox_check_empty (const char *);
 
110
+void mbox_reset_atime (CONTEXT *, struct stat *);
 
111
 
 
112
 int mh_read_dir (CONTEXT *, const char *);
 
113
 int mh_sync_mailbox (CONTEXT *, int *);