unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: derive correct timestamp in FCC unique name
@ 2012-06-13 20:01 Jesse Rosenthal
  2012-06-14  9:43 ` Tomi Ollila
  2012-06-14 17:16 ` [PATCHv2] " Jesse Rosenthal
  0 siblings, 2 replies; 6+ messages in thread
From: Jesse Rosenthal @ 2012-06-13 20:01 UTC (permalink / raw)
  To: notmuch


Previously, the timestamp at the beginning of the FCC maildir unique
maildir name was derived incorrectly, thanks to an integer
overflow. This changes the derivation of timestamp to float
arithmetic, and so gets the number correct. (It is still formatted
with "%d" so it will show up as an integer.)

This change is mostly a question of consistency, since the unique name
is arbitrary anyway. But since most people use timestamps, and that was
the original intention here as well, we might as well.

Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
---
 emacs/notmuch-maildir-fcc.el |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index dcfbc4b..6fd8ff9 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -141,7 +141,7 @@ will NOT be removed or replaced."
 
 (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
    (let* ((ct (current-time))
-	  (timeid (+ (* (car ct) 65536) (cadr ct)))
+	  (timeid (+ (* (car ct) 65536.0) (cadr ct)))
 	  (microseconds (car (cdr (cdr ct))))
 	  (hostname (notmuch-maildir-fcc-host-fixer system-name)))
      (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] emacs: derive correct timestamp in FCC unique name
  2012-06-13 20:01 [PATCH] emacs: derive correct timestamp in FCC unique name Jesse Rosenthal
@ 2012-06-14  9:43 ` Tomi Ollila
  2012-06-14 16:35   ` Jesse Rosenthal
  2012-06-14 17:16 ` [PATCHv2] " Jesse Rosenthal
  1 sibling, 1 reply; 6+ messages in thread
From: Tomi Ollila @ 2012-06-14  9:43 UTC (permalink / raw)
  To: Jesse Rosenthal, notmuch

On Wed, Jun 13 2012, Jesse Rosenthal <jrosenthal@jhu.edu> wrote:

> Previously, the timestamp at the beginning of the FCC maildir unique
> maildir name was derived incorrectly, thanks to an integer
> overflow. This changes the derivation of timestamp to float
> arithmetic, and so gets the number correct. (It is still formatted
> with "%d" so it will show up as an integer.)
>
> This change is mostly a question of consistency, since the unique name
> is arbitrary anyway. But since most people use timestamps, and that was
> the original intention here as well, we might as well.
>
> Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
> ---

Good point -- did some experiments (on 32bit machine, on 64 (* 65536 *65536)
just works OK (4294967296).

(insert (format " %d" (* 8191 65536)))  536805376
(insert (format " %d" (* 8192 65536)))  -536870912

Wraps now (many times already)

(insert (format "  %d" (* 32767 65536.0)))  2147418112
(insert (format "  %d" (* 32768 65536.0)))  -2147483648

Wraps Tue Jan 19 03:14:08 2038 UTC

(insert (format "  %0.f" (* 32768 65536.0)))  2147483648
(insert (format "  %0.f" (* 65536 65536.0)))  4294967296

Does not wrap.

On emacs window you can re-experiment by typing C-x C-e after last 
closing ')' on line.

(float-time '(32767 65536)) -> 2147418112.0 (minibuffer output)
(float-time '(32768 65536)) -> error "Invalid time specification"

On 64-bit machine this latest work ok; i.e 2147483648.0 is returned.

Alternatives:

1) Use current patch, filenames will have extra '-' in 2038 on 32-bit
systems.

2) Drop 'timeid' and replace it with (float-time) in `format` call a few
lines in original source after the patch context below -- No idea
how (float-time) works on 32-bit systems after 2038.

3) Use "%0.f" in format string instead of "%d" (there is no "%ld" or "%u"
sequences for `format`. I wonder what (current-time-string) in current
emacs return in 2038 (maybe I test (sometime(tm)) with (lib)faketime). 

I suggest option #2.

Tomi

>  emacs/notmuch-maildir-fcc.el |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
> index dcfbc4b..6fd8ff9 100644
> --- a/emacs/notmuch-maildir-fcc.el
> +++ b/emacs/notmuch-maildir-fcc.el
> @@ -141,7 +141,7 @@ will NOT be removed or replaced."
>  
>  (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
>     (let* ((ct (current-time))
> -	  (timeid (+ (* (car ct) 65536) (cadr ct)))
> +	  (timeid (+ (* (car ct) 65536.0) (cadr ct)))
>  	  (microseconds (car (cdr (cdr ct))))
>  	  (hostname (notmuch-maildir-fcc-host-fixer system-name)))
>       (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
> -- 
> 1.7.9.5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] emacs: derive correct timestamp in FCC unique name
  2012-06-14  9:43 ` Tomi Ollila
@ 2012-06-14 16:35   ` Jesse Rosenthal
  0 siblings, 0 replies; 6+ messages in thread
From: Jesse Rosenthal @ 2012-06-14 16:35 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Hi, 

thanks for thinking this through.

On Thu, 14 Jun 2012, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Alternatives:
>
> 1) Use current patch, filenames will have extra '-' in 2038 on 32-bit
> systems.

Well, that assumes there is still the same arithmetic operations -- the
calendar issue will probably push them to either auto-convert to float
or use bignum. But still, assuming that in 2038, people are still on
32bit machines, it seems we should minimize the amount of things that
need to be fixed. 

So I agree that...

> 2) Drop 'timeid' and replace it with (float-time) in `format` call a few
> lines in original source after the patch context below -- No idea
> how (float-time) works on 32-bit systems after 2038.

is probably the best. They'll have to deal with their time_t (again,
assuming the unlikely existence of 32bit machines then) but this doesn't
depend on their arithemetic. 

I'll send a revision to this thread.

> I suggest option #2.
>
> Tomi

Thanks again,
Jesse

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCHv2] emacs: derive correct timestamp in FCC unique name
  2012-06-13 20:01 [PATCH] emacs: derive correct timestamp in FCC unique name Jesse Rosenthal
  2012-06-14  9:43 ` Tomi Ollila
@ 2012-06-14 17:16 ` Jesse Rosenthal
  2012-06-14 19:04   ` Tomi Ollila
  2012-06-22 10:45   ` David Bremner
  1 sibling, 2 replies; 6+ messages in thread
From: Jesse Rosenthal @ 2012-06-14 17:16 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila


Previously, the timestamp at the beginning of the FCC unique maildir
name was derived incorrectly, thanks to an integer overflow. This
changes the derivation of timestamp to use a float, and so will get
the number correct at least until 2038. (It is still formatted with
"%d" so it will show up as an integer.) Should we need to change it in
the next 26 years to take the unix millenium into account, it will be
invisible to users.

This change is mostly a question of consistency, since the unique name
is arbitrary anyway. But since most people use timestamps, and that was
the original intention here as well, we might as well.

Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
---
 emacs/notmuch-maildir-fcc.el |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index dcfbc4b..07eedba 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -140,13 +140,12 @@ will NOT be removed or replaced."
 			    t))
 
 (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
-   (let* ((ct (current-time))
-	  (timeid (+ (* (car ct) 65536) (cadr ct)))
-	  (microseconds (car (cdr (cdr ct))))
+   (let* ((ftime (float-time))
+	  (microseconds (mod (* 1000000 ftime) 1000000))
 	  (hostname (notmuch-maildir-fcc-host-fixer system-name)))
      (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
      (format "%d.%d_%d_%d.%s"
-	     timeid
+	     ftime
 	     (emacs-pid)
 	     microseconds
 	     notmuch-maildir-fcc-count
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCHv2] emacs: derive correct timestamp in FCC unique name
  2012-06-14 17:16 ` [PATCHv2] " Jesse Rosenthal
@ 2012-06-14 19:04   ` Tomi Ollila
  2012-06-22 10:45   ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2012-06-14 19:04 UTC (permalink / raw)
  To: Jesse Rosenthal, notmuch

On Thu, Jun 14 2012, Jesse Rosenthal <jrosenthal@jhu.edu> wrote:

> Previously, the timestamp at the beginning of the FCC unique maildir
> name was derived incorrectly, thanks to an integer overflow. This
> changes the derivation of timestamp to use a float, and so will get
> the number correct at least until 2038. (It is still formatted with
> "%d" so it will show up as an integer.) Should we need to change it in
> the next 26 years to take the unix millenium into account, it will be
> invisible to users.
>
> This change is mostly a question of consistency, since the unique name
> is arbitrary anyway. But since most people use timestamps, and that was
> the original intention here as well, we might as well.
>
> Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
> ---


+1


Tomi

>  emacs/notmuch-maildir-fcc.el |    7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
> index dcfbc4b..07eedba 100644
> --- a/emacs/notmuch-maildir-fcc.el
> +++ b/emacs/notmuch-maildir-fcc.el
> @@ -140,13 +140,12 @@ will NOT be removed or replaced."
>  			    t))
>  
>  (defun notmuch-maildir-fcc-make-uniq-maildir-id ()
> -   (let* ((ct (current-time))
> -	  (timeid (+ (* (car ct) 65536) (cadr ct)))
> -	  (microseconds (car (cdr (cdr ct))))
> +   (let* ((ftime (float-time))
> +	  (microseconds (mod (* 1000000 ftime) 1000000))
>  	  (hostname (notmuch-maildir-fcc-host-fixer system-name)))
>       (setq notmuch-maildir-fcc-count (+ notmuch-maildir-fcc-count 1))
>       (format "%d.%d_%d_%d.%s"
> -	     timeid
> +	     ftime
>  	     (emacs-pid)
>  	     microseconds
>  	     notmuch-maildir-fcc-count
> -- 
> 1.7.9.5
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCHv2] emacs: derive correct timestamp in FCC unique name
  2012-06-14 17:16 ` [PATCHv2] " Jesse Rosenthal
  2012-06-14 19:04   ` Tomi Ollila
@ 2012-06-22 10:45   ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2012-06-22 10:45 UTC (permalink / raw)
  To: Jesse Rosenthal, notmuch

Jesse Rosenthal <jrosenthal@jhu.edu> writes:


> This change is mostly a question of consistency, since the unique name
> is arbitrary anyway. But since most people use timestamps, and that was
> the original intention here as well, we might as well.

pushed.

d

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-22 10:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-13 20:01 [PATCH] emacs: derive correct timestamp in FCC unique name Jesse Rosenthal
2012-06-14  9:43 ` Tomi Ollila
2012-06-14 16:35   ` Jesse Rosenthal
2012-06-14 17:16 ` [PATCHv2] " Jesse Rosenthal
2012-06-14 19:04   ` Tomi Ollila
2012-06-22 10:45   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).