emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master d0c77a1: Remove some assumptions about timestamp format


From: Michael Albinus
Subject: Re: master d0c77a1: Remove some assumptions about timestamp format
Date: Tue, 25 Sep 2018 12:09:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

address@hidden (Paul Eggert) writes:

Hi Paul,

>     Remove some assumptions about timestamp format
>     
>     These changes remove some assumptions of Lisp code on timestamp
>     format.  Although we’re not going to change the default format any
>     time soon, I went looking for code that was too intimate about
>     details of timestamp format and removed assumptions where this was
>     easy to do with current Emacs primitives.
>     * test/lisp/calendar/parse-time-tests.el (parse-time-tests):
>     * test/lisp/emacs-lisp/timer-tests.el (timer-test-multiple-of-time):
>     * test/lisp/net/tramp-tests.el:
>     (tramp-test19-directory-files-and-attributes)
>     (tramp-test22-file-times, tramp-test23-visited-file-modtime):
>     Don’t assume detailed format of returned Lisp timestamps.

> diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
> index 55884f3..7901355 100644
> --- a/test/lisp/net/tramp-tests.el
> +++ b/test/lisp/net/tramp-tests.el
> @@ -2882,16 +2882,16 @@ This tests also `file-readable-p', `file-regular-p' 
> and
>           ;; able to return the date correctly.  They say "don't know".
>           (dolist (elt attr)
>             (unless
> -               (equal
> -                (nth
> -                 5 (file-attributes (expand-file-name (car elt) tmp-name2)))
> -                '(0 0))
> +               (zerop
> +                (float-time
> +                 (nth 5 (file-attributes
> +                         (expand-file-name (car elt) tmp-name2)))))
>               (should
>                (equal (file-attributes (expand-file-name (car elt) tmp-name2))
>                       (cdr elt)))))
>           (setq attr (directory-files-and-attributes tmp-name2 'full))
>           (dolist (elt attr)
> -           (unless (equal (nth 5 (file-attributes (car elt))) '(0 0))
> +           (unless (zerop (float-time (nth 5 (file-attributes (car elt)))))
>               (should
>                (equal (file-attributes (car elt)) (cdr elt)))))
>           (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
> @@ -3215,14 +3215,14 @@ This tests also `make-symbolic-link', `file-truename' 
> and `add-name-to-file'."
>           (write-region "foo" nil tmp-name1)
>           (should (file-exists-p tmp-name1))
>           (should (consp (nth 5 (file-attributes tmp-name1))))
> -         ;; '(0 0) means don't know, and will be replaced by
> -         ;; `current-time'.  Therefore, we use '(0 1).  We skip the
> +         ;; A zero timestamp means don't know, and will be replaced by
> +         ;; `current-time'.  Therefore, use timestamp 1.  Skip the
>           ;; test, if the remote handler is not able to set the
>           ;; correct time.
>           (skip-unless (set-file-times tmp-name1 (seconds-to-time 1)))
>           ;; Dumb remote shells without perl(1) or stat(1) are not
>           ;; able to return the date correctly.  They say "don't know".
> -         (unless (equal (nth 5 (file-attributes tmp-name1)) '(0 0))
> +         (unless (zerop (float-time (nth 5 (file-attributes tmp-name1))))
>             (should
>              (equal (nth 5 (file-attributes tmp-name1)) (seconds-to-time 1)))
>             (write-region "bla" nil tmp-name2)
> @@ -3250,9 +3250,9 @@ This tests also `make-symbolic-link', `file-truename' 
> and `add-name-to-file'."
>           (with-temp-buffer
>             (insert-file-contents tmp-name)
>             (should (verify-visited-file-modtime))
> -           (set-visited-file-modtime '(0 1))
> +              (set-visited-file-modtime (seconds-to-time 1))
>             (should (verify-visited-file-modtime))
> -           (should (equal (visited-file-modtime) '(0 1 0 0)))))
> +           (should (= 1 (float-time (visited-file-modtime))))))
>  
>       ;; Cleanup.
>       (ignore-errors (delete-file tmp-name))))))

In the different tramp*.el files, '(0 0) is explicitly quoted as "don't
know value". This is there for ages.

If you want to change this in the tests, it shall be changed in
tramp*.el as well. Maybe it would be even worth an own constant?
Something like

(defconst time-dont-know (seconds-to-time 0)
  "A time value indicating an unknown time.")

If you like, it could even have the value 0 instead of (seconds-to-time
0). But this would also introduce "some assumptions of Lisp code on
timestamp format" - what you try to avoid.

Best regards, Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]