diff options
| author | Michael Albinus | 2018-09-29 15:33:48 +0200 |
|---|---|---|
| committer | Michael Albinus | 2018-09-29 15:33:48 +0200 |
| commit | ce0da8a427467a2a5e5636f4d69eb56b56b0925e (patch) | |
| tree | 5de46dcce14f9a61af05f7ac7b658e877eab7d30 | |
| parent | 9284e22676a80789a95c3df3b74ac938a0f5eeaa (diff) | |
| download | emacs-ce0da8a427467a2a5e5636f4d69eb56b56b0925e.tar.gz emacs-ce0da8a427467a2a5e5636f4d69eb56b56b0925e.zip | |
Rework time-* functions in Tramp
* doc/misc/emacs-mime.texi (time-date): Add time-equal-p.
* lisp/net/tramp-compat.el (tramp-compat-time-equal-p): New defsubst.
* lisp/net/tramp.el (tramp-file-name-handler): Remove `debug'
error handler.
(tramp-half-a-year): Remove.
(tramp-time-dont-know, tramp-time-doesnt-exist): New defconst.
(tramp-time-diff): Remove compat code.
(tramp-handle-set-visited-file-modtime)
(tramp-handle-verify-visited-file-modtime):
* lisp/net/tramp-adb.el (tramp-do-parse-file-attributes-with-ls)
(tramp-adb-handle-set-file-times):
* lisp/net/tramp-sh.el (tramp-do-file-attributes-with-ls)
(tramp-sh-handle-set-visited-file-modtime)
(tramp-sh-handle-verify-visited-file-modtime)
(tramp-sh-handle-set-file-times)
(tramp-sh-handle-file-newer-than-file-p):
Use `tramp-time-dont-know', `tramp-time-doesnt-exist' and
`tramp-compat-time-equal-p'.
(tramp-sh-handle-verify-visited-file-modtime): Simplify check.
* lisp/net/tramp-smb.el (tramp-smb-handle-file-attributes)
(tramp-smb-read-file-entry): Use `tramp-time-dont-know'.
(tramp-smb-handle-insert-directory): Adapt half-a-year check.
* src/editfns.c (Ftime_equal_p): Adapt docstring.
* test/lisp/net/tramp-tests.el
(tramp-test19-directory-files-and-attributes)
(tramp-test22-file-times): Use `tramp-compat-time-equal-p' and
`tramp-time-dont-know'.
(tramp-test23-visited-file-modtime): Extend test.
| -rw-r--r-- | doc/misc/emacs-mime.texi | 7 | ||||
| -rw-r--r-- | lisp/net/tramp-adb.el | 8 | ||||
| -rw-r--r-- | lisp/net/tramp-cache.el | 5 | ||||
| -rw-r--r-- | lisp/net/tramp-compat.el | 8 | ||||
| -rw-r--r-- | lisp/net/tramp-gvfs.el | 2 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 55 | ||||
| -rw-r--r-- | lisp/net/tramp-smb.el | 31 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 33 | ||||
| -rw-r--r-- | src/editfns.c | 4 | ||||
| -rw-r--r-- | test/lisp/net/tramp-tests.el | 28 |
10 files changed, 97 insertions, 84 deletions
diff --git a/doc/misc/emacs-mime.texi b/doc/misc/emacs-mime.texi index 45f37fb8557..9280311b5c9 100644 --- a/doc/misc/emacs-mime.texi +++ b/doc/misc/emacs-mime.texi | |||
| @@ -1561,6 +1561,9 @@ Here's a bunch of time/date/second/day examples: | |||
| 1561 | (time-less-p '(13818 19266) '(13818 19145)) | 1561 | (time-less-p '(13818 19266) '(13818 19145)) |
| 1562 | @result{} nil | 1562 | @result{} nil |
| 1563 | 1563 | ||
| 1564 | (time-equal-p '(13818 19266) '(13818 19145)) | ||
| 1565 | @result{} nil | ||
| 1566 | |||
| 1564 | (time-subtract '(13818 19266) '(13818 19145)) | 1567 | (time-subtract '(13818 19266) '(13818 19145)) |
| 1565 | @result{} (0 121) | 1568 | @result{} (0 121) |
| 1566 | 1569 | ||
| @@ -1641,6 +1644,10 @@ return a ``zero'' time. | |||
| 1641 | Take two times and say whether the first time is less (i.e., earlier) | 1644 | Take two times and say whether the first time is less (i.e., earlier) |
| 1642 | than the second time. (This is a built-in function.) | 1645 | than the second time. (This is a built-in function.) |
| 1643 | 1646 | ||
| 1647 | @item time-equal-p | ||
| 1648 | Check, whether two time values are equal. The time values must not be | ||
| 1649 | in the same format. (This is a built-in function.) | ||
| 1650 | |||
| 1644 | @item time-since | 1651 | @item time-since |
| 1645 | Take a time and return a time saying how long it was since that time. | 1652 | Take a time and return a time saying how long it was since that time. |
| 1646 | 1653 | ||
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 35b0fdda623..36374f88e0d 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el | |||
| @@ -411,9 +411,9 @@ pass to the OPERATION." | |||
| 411 | ;; no way to handle numeric ids in Androids ash | 411 | ;; no way to handle numeric ids in Androids ash |
| 412 | (if (eq id-format 'integer) 0 uid) | 412 | (if (eq id-format 'integer) 0 uid) |
| 413 | (if (eq id-format 'integer) 0 gid) | 413 | (if (eq id-format 'integer) 0 gid) |
| 414 | '(0 0) ; atime | 414 | tramp-time-dont-know ; atime |
| 415 | (date-to-time date) ; mtime | 415 | (date-to-time date) ; mtime |
| 416 | '(0 0) ; ctime | 416 | tramp-time-dont-know ; ctime |
| 417 | size | 417 | size |
| 418 | mod-string | 418 | mod-string |
| 419 | ;; fake | 419 | ;; fake |
| @@ -725,7 +725,9 @@ But handle the case, if the \"test\" command is not available." | |||
| 725 | (with-parsed-tramp-file-name filename nil | 725 | (with-parsed-tramp-file-name filename nil |
| 726 | (tramp-flush-file-properties v (file-name-directory localname)) | 726 | (tramp-flush-file-properties v (file-name-directory localname)) |
| 727 | (tramp-flush-file-properties v localname) | 727 | (tramp-flush-file-properties v localname) |
| 728 | (let ((time (if (or (null time) (equal time '(0 0))) | 728 | (let ((time (if (or (null time) |
| 729 | (tramp-compat-time-equal-p time tramp-time-doesnt-exist) | ||
| 730 | (tramp-compat-time-equal-p time tramp-time-dont-know)) | ||
| 729 | (current-time) | 731 | (current-time) |
| 730 | time))) | 732 | time))) |
| 731 | (tramp-adb-send-command-and-check | 733 | (tramp-adb-send-command-and-check |
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index b40a4d7edd6..ebb4254dab4 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el | |||
| @@ -118,9 +118,8 @@ Returns DEFAULT if not set." | |||
| 118 | (and (consp value) | 118 | (and (consp value) |
| 119 | (or (null remote-file-name-inhibit-cache) | 119 | (or (null remote-file-name-inhibit-cache) |
| 120 | (and (integerp remote-file-name-inhibit-cache) | 120 | (and (integerp remote-file-name-inhibit-cache) |
| 121 | (<= | 121 | (<= (tramp-time-diff (current-time) (car value)) |
| 122 | (tramp-time-diff (current-time) (car value)) | 122 | remote-file-name-inhibit-cache)) |
| 123 | remote-file-name-inhibit-cache)) | ||
| 124 | (and (consp remote-file-name-inhibit-cache) | 123 | (and (consp remote-file-name-inhibit-cache) |
| 125 | (time-less-p | 124 | (time-less-p |
| 126 | remote-file-name-inhibit-cache (car value))))) | 125 | remote-file-name-inhibit-cache (car value))))) |
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index bcfaf40ebc1..c3777e6e737 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el | |||
| @@ -247,6 +247,14 @@ If NAME is a remote file name, the local part of NAME is unquoted." | |||
| 247 | (funcall handler 'exec-path) | 247 | (funcall handler 'exec-path) |
| 248 | exec-path))))) | 248 | exec-path))))) |
| 249 | 249 | ||
| 250 | ;; `time-equal-p' has appeared in Emacs 27.1. | ||
| 251 | (if (fboundp 'time-equal-p) | ||
| 252 | (defalias 'tramp-compat-time-equal-p 'time-equal-p) | ||
| 253 | (defsubst tramp-compat-time-equal-p (t1 t2) | ||
| 254 | "Return non-nil if time value T1 is equal to time value T2. | ||
| 255 | A nil value for either argument stands for the current time." | ||
| 256 | (equal (or t1 (current-time)) (or t2 (current-time))))) | ||
| 257 | |||
| 250 | (add-hook 'tramp-unload-hook | 258 | (add-hook 'tramp-unload-hook |
| 251 | (lambda () | 259 | (lambda () |
| 252 | (unload-feature 'tramp-loaddefs 'force) | 260 | (unload-feature 'tramp-loaddefs 'force) |
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index f46ddc68ae4..c150edf3f13 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el | |||
| @@ -650,7 +650,7 @@ Return nil for null BYTE-ARRAY." | |||
| 650 | (cond | 650 | (cond |
| 651 | ((and (consp message) (characterp (car message))) | 651 | ((and (consp message) (characterp (car message))) |
| 652 | (format "%S" (tramp-gvfs-dbus-byte-array-to-string message))) | 652 | (format "%S" (tramp-gvfs-dbus-byte-array-to-string message))) |
| 653 | ((and (consp message) (not (consp (cdr message)))) | 653 | ((and (consp message) (atom (cdr message))) |
| 654 | (cons (tramp-gvfs-stringify-dbus-message (car message)) | 654 | (cons (tramp-gvfs-stringify-dbus-message (car message)) |
| 655 | (tramp-gvfs-stringify-dbus-message (cdr message)))) | 655 | (tramp-gvfs-stringify-dbus-message (cdr message)))) |
| 656 | ((consp message) | 656 | ((consp message) |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 64d208175f9..b2be43395f8 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -1348,13 +1348,10 @@ component is used as the target of the symlink." | |||
| 1348 | res-uid | 1348 | res-uid |
| 1349 | ;; 3. File gid. | 1349 | ;; 3. File gid. |
| 1350 | res-gid | 1350 | res-gid |
| 1351 | ;; 4. Last access time, as a list of integers. Normally | 1351 | ;; 4. Last access time. |
| 1352 | ;; this would be in the same format as `current-time', but | 1352 | ;; 5. Last modification time. |
| 1353 | ;; the subseconds part is not currently implemented, and | 1353 | ;; 6. Last status change time. |
| 1354 | ;; (0 0) denotes an unknown time. | 1354 | tramp-time-dont-know tramp-time-dont-know tramp-time-dont-know |
| 1355 | ;; 5. Last modification time, likewise. | ||
| 1356 | ;; 6. Last status change time, likewise. | ||
| 1357 | '(0 0) '(0 0) '(0 0) ;CCC how to find out? | ||
| 1358 | ;; 7. Size in bytes (-1, if number is out of range). | 1355 | ;; 7. Size in bytes (-1, if number is out of range). |
| 1359 | res-size | 1356 | res-size |
| 1360 | ;; 8. File modes, as a string of ten letters or dashes as in ls -l. | 1357 | ;; 8. File modes, as a string of ten letters or dashes as in ls -l. |
| @@ -1420,13 +1417,10 @@ component is used as the target of the symlink." | |||
| 1420 | (with-parsed-tramp-file-name f nil | 1417 | (with-parsed-tramp-file-name f nil |
| 1421 | (let* ((remote-file-name-inhibit-cache t) | 1418 | (let* ((remote-file-name-inhibit-cache t) |
| 1422 | (attr (file-attributes f)) | 1419 | (attr (file-attributes f)) |
| 1423 | ;; '(-1 65535) means file doesn't exists yet. | ||
| 1424 | (modtime (or (tramp-compat-file-attribute-modification-time attr) | 1420 | (modtime (or (tramp-compat-file-attribute-modification-time attr) |
| 1425 | '(-1 65535)))) | 1421 | tramp-time-doesnt-exist))) |
| 1426 | (setq coding-system-used last-coding-system-used) | 1422 | (setq coding-system-used last-coding-system-used) |
| 1427 | ;; We use '(0 0) as a don't-know value. See also | 1423 | (if (not (tramp-compat-time-equal-p modtime tramp-time-dont-know)) |
| 1428 | ;; `tramp-do-file-attributes-with-ls'. | ||
| 1429 | (if (not (equal modtime '(0 0))) | ||
| 1430 | (tramp-run-real-handler 'set-visited-file-modtime (list modtime)) | 1424 | (tramp-run-real-handler 'set-visited-file-modtime (list modtime)) |
| 1431 | (progn | 1425 | (progn |
| 1432 | (tramp-send-command | 1426 | (tramp-send-command |
| @@ -1455,7 +1449,7 @@ of." | |||
| 1455 | ;; recorded last modification time, or there is no established | 1449 | ;; recorded last modification time, or there is no established |
| 1456 | ;; connection. | 1450 | ;; connection. |
| 1457 | (if (or (not f) | 1451 | (if (or (not f) |
| 1458 | (eq (visited-file-modtime) 0) | 1452 | (zerop (visited-file-modtime)) |
| 1459 | (not (file-remote-p f nil 'connected))) | 1453 | (not (file-remote-p f nil 'connected))) |
| 1460 | t | 1454 | t |
| 1461 | (with-parsed-tramp-file-name f nil | 1455 | (with-parsed-tramp-file-name f nil |
| @@ -1466,16 +1460,10 @@ of." | |||
| 1466 | 1460 | ||
| 1467 | (cond | 1461 | (cond |
| 1468 | ;; File exists, and has a known modtime. | 1462 | ;; File exists, and has a known modtime. |
| 1469 | ((and attr (not (equal modtime '(0 0)))) | 1463 | ((and attr |
| 1470 | (< (abs (tramp-time-diff | 1464 | (not |
| 1471 | modtime | 1465 | (tramp-compat-time-equal-p modtime tramp-time-dont-know))) |
| 1472 | ;; For compatibility, deal with both the old | 1466 | (< (abs (tramp-time-diff modtime mt)) 2)) |
| 1473 | ;; (HIGH . LOW) and the new (HIGH LOW) return | ||
| 1474 | ;; values of `visited-file-modtime'. | ||
| 1475 | (if (atom (cdr mt)) | ||
| 1476 | (list (car mt) (cdr mt)) | ||
| 1477 | mt))) | ||
| 1478 | 2)) | ||
| 1479 | ;; Modtime has the don't know value. | 1467 | ;; Modtime has the don't know value. |
| 1480 | (attr | 1468 | (attr |
| 1481 | (tramp-send-command | 1469 | (tramp-send-command |
| @@ -1491,7 +1479,7 @@ of." | |||
| 1491 | v localname "visited-file-modtime-ild" ""))) | 1479 | v localname "visited-file-modtime-ild" ""))) |
| 1492 | ;; If file does not exist, say it is not modified if and | 1480 | ;; If file does not exist, say it is not modified if and |
| 1493 | ;; only if that agrees with the buffer's record. | 1481 | ;; only if that agrees with the buffer's record. |
| 1494 | (t (equal mt '(-1 65535)))))))))) | 1482 | (t (tramp-compat-time-equal-p mt tramp-time-doesnt-exist))))))))) |
| 1495 | 1483 | ||
| 1496 | (defun tramp-sh-handle-set-file-modes (filename mode) | 1484 | (defun tramp-sh-handle-set-file-modes (filename mode) |
| 1497 | "Like `set-file-modes' for Tramp files." | 1485 | "Like `set-file-modes' for Tramp files." |
| @@ -1510,9 +1498,12 @@ of." | |||
| 1510 | (when (tramp-get-remote-touch v) | 1498 | (when (tramp-get-remote-touch v) |
| 1511 | (tramp-flush-file-properties v (file-name-directory localname)) | 1499 | (tramp-flush-file-properties v (file-name-directory localname)) |
| 1512 | (tramp-flush-file-properties v localname) | 1500 | (tramp-flush-file-properties v localname) |
| 1513 | (let ((time (if (or (null time) (equal time '(0 0))) | 1501 | (let ((time |
| 1514 | (current-time) | 1502 | (if (or (null time) |
| 1515 | time))) | 1503 | (tramp-compat-time-equal-p time tramp-time-doesnt-exist) |
| 1504 | (tramp-compat-time-equal-p time tramp-time-dont-know)) | ||
| 1505 | (current-time) | ||
| 1506 | time))) | ||
| 1516 | (tramp-send-command-and-check | 1507 | (tramp-send-command-and-check |
| 1517 | v (format | 1508 | v (format |
| 1518 | "env TZ=UTC %s %s %s" | 1509 | "env TZ=UTC %s %s %s" |
| @@ -1685,11 +1676,13 @@ be non-negative integers." | |||
| 1685 | (fa2 (file-attributes file2))) | 1676 | (fa2 (file-attributes file2))) |
| 1686 | (if (and | 1677 | (if (and |
| 1687 | (not | 1678 | (not |
| 1688 | (equal (tramp-compat-file-attribute-modification-time fa1) | 1679 | (tramp-compat-time-equal-p |
| 1689 | '(0 0))) | 1680 | (tramp-compat-file-attribute-modification-time fa1) |
| 1681 | tramp-time-dont-know)) | ||
| 1690 | (not | 1682 | (not |
| 1691 | (equal (tramp-compat-file-attribute-modification-time fa2) | 1683 | (tramp-compat-time-equal-p |
| 1692 | '(0 0)))) | 1684 | (tramp-compat-file-attribute-modification-time fa2) |
| 1685 | tramp-time-dont-know))) | ||
| 1693 | (> 0 (tramp-time-diff | 1686 | (> 0 (tramp-time-diff |
| 1694 | (tramp-compat-file-attribute-modification-time fa2) | 1687 | (tramp-compat-file-attribute-modification-time fa2) |
| 1695 | (tramp-compat-file-attribute-modification-time fa1))) | 1688 | (tramp-compat-file-attribute-modification-time fa1))) |
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 583acbde03c..a97b8017300 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el | |||
| @@ -817,18 +817,18 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 817 | ;; Check result. | 817 | ;; Check result. |
| 818 | (when entry | 818 | (when entry |
| 819 | (list (and (string-match "d" (nth 1 entry)) | 819 | (list (and (string-match "d" (nth 1 entry)) |
| 820 | t) ;0 file type | 820 | t) ;0 file type |
| 821 | -1 ;1 link count | 821 | -1 ;1 link count |
| 822 | uid ;2 uid | 822 | uid ;2 uid |
| 823 | gid ;3 gid | 823 | gid ;3 gid |
| 824 | '(0 0) ;4 atime | 824 | tramp-time-dont-know ;4 atime |
| 825 | (nth 3 entry) ;5 mtime | 825 | (nth 3 entry) ;5 mtime |
| 826 | '(0 0) ;6 ctime | 826 | tramp-time-dont-know ;6 ctime |
| 827 | (nth 2 entry) ;7 size | 827 | (nth 2 entry) ;7 size |
| 828 | (nth 1 entry) ;8 mode | 828 | (nth 1 entry) ;8 mode |
| 829 | nil ;9 gid weird | 829 | nil ;9 gid weird |
| 830 | inode ;10 inode number | 830 | inode ;10 inode number |
| 831 | device)))))))) ;11 file system number | 831 | device)))))))) ;11 file system number |
| 832 | 832 | ||
| 833 | (defun tramp-smb-do-file-attributes-with-stat (vec &optional id-format) | 833 | (defun tramp-smb-do-file-attributes-with-stat (vec &optional id-format) |
| 834 | "Implement `file-attributes' for Tramp files using stat command." | 834 | "Implement `file-attributes' for Tramp files using stat command." |
| @@ -1085,8 +1085,9 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." | |||
| 1085 | (or (tramp-compat-file-attribute-group-id attr) "nogroup") | 1085 | (or (tramp-compat-file-attribute-group-id attr) "nogroup") |
| 1086 | (or (tramp-compat-file-attribute-size attr) (nth 2 x)) | 1086 | (or (tramp-compat-file-attribute-size attr) (nth 2 x)) |
| 1087 | (format-time-string | 1087 | (format-time-string |
| 1088 | (if (time-less-p (time-subtract (current-time) (nth 3 x)) | 1088 | (if (time-less-p |
| 1089 | tramp-half-a-year) | 1089 | ;; Half a year. |
| 1090 | (time-since (nth 3 x)) (days-to-time 183)) | ||
| 1090 | "%b %e %R" | 1091 | "%b %e %R" |
| 1091 | "%b %e %Y") | 1092 | "%b %e %Y") |
| 1092 | (nth 3 x))))) ; date | 1093 | (nth 3 x))))) ; date |
| @@ -1816,7 +1817,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)." | |||
| 1816 | sec min hour day | 1817 | sec min hour day |
| 1817 | (cdr (assoc (downcase month) parse-time-months)) | 1818 | (cdr (assoc (downcase month) parse-time-months)) |
| 1818 | year) | 1819 | year) |
| 1819 | '(0 0))) | 1820 | tramp-time-dont-know)) |
| 1820 | (list localname mode size mtime)))) | 1821 | (list localname mode size mtime)))) |
| 1821 | 1822 | ||
| 1822 | (defun tramp-smb-get-cifs-capabilities (vec) | 1823 | (defun tramp-smb-get-cifs-capabilities (vec) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 723b35c9e7b..e1602db1492 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3602,13 +3602,11 @@ support symbolic links." | |||
| 3602 | (buffer-name))) | 3602 | (buffer-name))) |
| 3603 | (unless time-list | 3603 | (unless time-list |
| 3604 | (let ((remote-file-name-inhibit-cache t)) | 3604 | (let ((remote-file-name-inhibit-cache t)) |
| 3605 | ;; '(-1 65535) means file doesn't exists yet. | ||
| 3606 | (setq time-list | 3605 | (setq time-list |
| 3607 | (or (tramp-compat-file-attribute-modification-time | 3606 | (or (tramp-compat-file-attribute-modification-time |
| 3608 | (file-attributes (buffer-file-name))) | 3607 | (file-attributes (buffer-file-name))) |
| 3609 | '(-1 65535))))) | 3608 | tramp-time-doesnt-exist)))) |
| 3610 | ;; We use '(0 0) as a don't-know value. | 3609 | (unless (tramp-compat-time-equal-p time-list tramp-time-dont-know) |
| 3611 | (unless (equal time-list '(0 0)) | ||
| 3612 | (tramp-run-real-handler 'set-visited-file-modtime (list time-list)))) | 3610 | (tramp-run-real-handler 'set-visited-file-modtime (list time-list)))) |
| 3613 | 3611 | ||
| 3614 | (defun tramp-handle-verify-visited-file-modtime (&optional buf) | 3612 | (defun tramp-handle-verify-visited-file-modtime (&optional buf) |
| @@ -3634,21 +3632,14 @@ of." | |||
| 3634 | 3632 | ||
| 3635 | (cond | 3633 | (cond |
| 3636 | ;; File exists, and has a known modtime. | 3634 | ;; File exists, and has a known modtime. |
| 3637 | ((and attr (not (equal modtime '(0 0)))) | 3635 | ((and attr |
| 3638 | (< (abs (tramp-time-diff | 3636 | (not (tramp-compat-time-equal-p modtime tramp-time-dont-know))) |
| 3639 | modtime | 3637 | (< (abs (tramp-time-diff modtime mt)) 2)) |
| 3640 | ;; For compatibility, deal with both the old | ||
| 3641 | ;; (HIGH . LOW) and the new (HIGH LOW) return | ||
| 3642 | ;; values of `visited-file-modtime'. | ||
| 3643 | (if (atom (cdr mt)) | ||
| 3644 | (list (car mt) (cdr mt)) | ||
| 3645 | mt))) | ||
| 3646 | 2)) | ||
| 3647 | ;; Modtime has the don't know value. | 3638 | ;; Modtime has the don't know value. |
| 3648 | (attr t) | 3639 | (attr t) |
| 3649 | ;; If file does not exist, say it is not modified if and | 3640 | ;; If file does not exist, say it is not modified if and |
| 3650 | ;; only if that agrees with the buffer's record. | 3641 | ;; only if that agrees with the buffer's record. |
| 3651 | (t (equal mt '(-1 65535))))))))) | 3642 | (t (tramp-compat-time-equal-p mt tramp-time-doesnt-exist)))))))) |
| 3652 | 3643 | ||
| 3653 | ;; This is used in tramp-gvfs.el and tramp-sh.el. | 3644 | ;; This is used in tramp-gvfs.el and tramp-sh.el. |
| 3654 | (defconst tramp-gio-events | 3645 | (defconst tramp-gio-events |
| @@ -4531,17 +4522,19 @@ Invokes `password-read' if available, `read-passwd' else." | |||
| 4531 | :host ,host-port :port ,method)) | 4522 | :host ,host-port :port ,method)) |
| 4532 | (password-cache-remove (tramp-make-tramp-file-name vec 'noloc 'nohop)))) | 4523 | (password-cache-remove (tramp-make-tramp-file-name vec 'noloc 'nohop)))) |
| 4533 | 4524 | ||
| 4534 | ;; Snarfed code from time-date.el. | 4525 | ;;;###tramp-autoload |
| 4526 | (defconst tramp-time-dont-know '(0 0 0 1000) | ||
| 4527 | "An invalid time value, used as \"Don’t know\" value.") | ||
| 4535 | 4528 | ||
| 4536 | (defconst tramp-half-a-year '(241 17024) | 4529 | ;;;###tramp-autoload |
| 4537 | "Evaluated by \"(days-to-time 183)\".") | 4530 | (defconst tramp-time-doesnt-exist '(-1 65535) |
| 4531 | "An invalid time value, used as \"Doesn’t exist\" value.") | ||
| 4538 | 4532 | ||
| 4539 | ;;;###tramp-autoload | 4533 | ;;;###tramp-autoload |
| 4540 | (defun tramp-time-diff (t1 t2) | 4534 | (defun tramp-time-diff (t1 t2) |
| 4541 | "Return the difference between the two times, in seconds. | 4535 | "Return the difference between the two times, in seconds. |
| 4542 | T1 and T2 are time values (as returned by `current-time' for example)." | 4536 | T1 and T2 are time values (as returned by `current-time' for example)." |
| 4543 | ;; Starting with Emacs 25.1, we could change this to use `time-subtract'. | 4537 | (float-time (time-subtract t1 t2))) |
| 4544 | (float-time (tramp-compat-funcall 'subtract-time t1 t2))) | ||
| 4545 | 4538 | ||
| 4546 | (defun tramp-unquote-shell-quote-argument (s) | 4539 | (defun tramp-unquote-shell-quote-argument (s) |
| 4547 | "Remove quotation prefix \"/:\" from string S, and quote it then for shell." | 4540 | "Remove quotation prefix \"/:\" from string S, and quote it then for shell." |
diff --git a/src/editfns.c b/src/editfns.c index daea7463871..47509c23d04 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1677,7 +1677,9 @@ See `current-time-string' for the various forms of a time value. */) | |||
| 1677 | } | 1677 | } |
| 1678 | 1678 | ||
| 1679 | DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0, | 1679 | DEFUN ("time-equal-p", Ftime_equal_p, Stime_equal_p, 2, 2, 0, |
| 1680 | doc: /* Return non-nil if T1 and T2 are equal time values. */) | 1680 | doc: /* Return non-nil if T1 and T2 are equal time values. |
| 1681 | A nil value for either argument stands for the current time. | ||
| 1682 | See `current-time-string' for the various forms of a time value. */) | ||
| 1681 | (Lisp_Object t1, Lisp_Object t2) | 1683 | (Lisp_Object t1, Lisp_Object t2) |
| 1682 | { | 1684 | { |
| 1683 | return time_cmp (t1, t2) == 0 ? Qt : Qnil; | 1685 | return time_cmp (t1, t2) == 0 ? Qt : Qnil; |
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 79013558fdb..523c7afada8 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el | |||
| @@ -2882,16 +2882,17 @@ This tests also `file-readable-p', `file-regular-p' and | |||
| 2882 | ;; able to return the date correctly. They say "don't know". | 2882 | ;; able to return the date correctly. They say "don't know". |
| 2883 | (dolist (elt attr) | 2883 | (dolist (elt attr) |
| 2884 | (unless | 2884 | (unless |
| 2885 | (zerop | 2885 | (tramp-compat-time-equal-p |
| 2886 | (float-time | 2886 | (nth |
| 2887 | (nth 5 (file-attributes | 2887 | 5 (file-attributes (expand-file-name (car elt) tmp-name2))) |
| 2888 | (expand-file-name (car elt) tmp-name2))))) | 2888 | tramp-time-dont-know) |
| 2889 | (should | 2889 | (should |
| 2890 | (equal (file-attributes (expand-file-name (car elt) tmp-name2)) | 2890 | (equal (file-attributes (expand-file-name (car elt) tmp-name2)) |
| 2891 | (cdr elt))))) | 2891 | (cdr elt))))) |
| 2892 | (setq attr (directory-files-and-attributes tmp-name2 'full)) | 2892 | (setq attr (directory-files-and-attributes tmp-name2 'full)) |
| 2893 | (dolist (elt attr) | 2893 | (dolist (elt attr) |
| 2894 | (unless (zerop (float-time (nth 5 (file-attributes (car elt))))) | 2894 | (unless (tramp-compat-time-equal-p |
| 2895 | (nth 5 (file-attributes (car elt))) tramp-time-dont-know) | ||
| 2895 | (should | 2896 | (should |
| 2896 | (equal (file-attributes (car elt)) (cdr elt))))) | 2897 | (equal (file-attributes (car elt)) (cdr elt))))) |
| 2897 | (setq attr (directory-files-and-attributes tmp-name2 nil "^b")) | 2898 | (setq attr (directory-files-and-attributes tmp-name2 nil "^b")) |
| @@ -3215,14 +3216,13 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3215 | (write-region "foo" nil tmp-name1) | 3216 | (write-region "foo" nil tmp-name1) |
| 3216 | (should (file-exists-p tmp-name1)) | 3217 | (should (file-exists-p tmp-name1)) |
| 3217 | (should (consp (nth 5 (file-attributes tmp-name1)))) | 3218 | (should (consp (nth 5 (file-attributes tmp-name1)))) |
| 3218 | ;; A zero timestamp means don't know, and will be replaced by | 3219 | ;; Skip the test, if the remote handler is not able to set |
| 3219 | ;; `current-time'. Therefore, use timestamp 1. Skip the | 3220 | ;; the correct time. |
| 3220 | ;; test, if the remote handler is not able to set the | ||
| 3221 | ;; correct time. | ||
| 3222 | (skip-unless (set-file-times tmp-name1 (seconds-to-time 1))) | 3221 | (skip-unless (set-file-times tmp-name1 (seconds-to-time 1))) |
| 3223 | ;; Dumb remote shells without perl(1) or stat(1) are not | 3222 | ;; Dumb remote shells without perl(1) or stat(1) are not |
| 3224 | ;; able to return the date correctly. They say "don't know". | 3223 | ;; able to return the date correctly. They say "don't know". |
| 3225 | (unless (zerop (float-time (nth 5 (file-attributes tmp-name1)))) | 3224 | (unless (tramp-compat-time-equal-p |
| 3225 | (nth 5 (file-attributes tmp-name1)) tramp-time-dont-know) | ||
| 3226 | (should | 3226 | (should |
| 3227 | (equal (nth 5 (file-attributes tmp-name1)) (seconds-to-time 1))) | 3227 | (equal (nth 5 (file-attributes tmp-name1)) (seconds-to-time 1))) |
| 3228 | (write-region "bla" nil tmp-name2) | 3228 | (write-region "bla" nil tmp-name2) |
| @@ -3252,6 +3252,14 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." | |||
| 3252 | (should (verify-visited-file-modtime)) | 3252 | (should (verify-visited-file-modtime)) |
| 3253 | (set-visited-file-modtime (seconds-to-time 1)) | 3253 | (set-visited-file-modtime (seconds-to-time 1)) |
| 3254 | (should (verify-visited-file-modtime)) | 3254 | (should (verify-visited-file-modtime)) |
| 3255 | (should (= 1 (float-time (visited-file-modtime)))) | ||
| 3256 | |||
| 3257 | ;; Checks with deleted file. | ||
| 3258 | (delete-file tmp-name) | ||
| 3259 | (dired-uncache tmp-name) | ||
| 3260 | (should (verify-visited-file-modtime)) | ||
| 3261 | (set-visited-file-modtime (seconds-to-time 1)) | ||
| 3262 | (should (verify-visited-file-modtime)) | ||
| 3255 | (should (= 1 (float-time (visited-file-modtime)))))) | 3263 | (should (= 1 (float-time (visited-file-modtime)))))) |
| 3256 | 3264 | ||
| 3257 | ;; Cleanup. | 3265 | ;; Cleanup. |