;; We do not test inodes and device numbers.
(setq attr (file-attributes tmp-name1))
(should (consp attr))
- (should (null (car attr)))
- (should (numberp (nth 1 attr))) ;; Link.
- (should (numberp (nth 2 attr))) ;; Uid.
- (should (numberp (nth 3 attr))) ;; Gid.
- ;; Last access time.
- (should (stringp (current-time-string (nth 4 attr))))
- ;; Last modification time.
- (should (stringp (current-time-string (nth 5 attr))))
- ;; Last status change time.
- (should (stringp (current-time-string (nth 6 attr))))
- (should (numberp (nth 7 attr))) ;; Size.
- (should (stringp (nth 8 attr))) ;; Modes.
+ (should (null (tramp-compat-file-attribute-type attr)))
+ (should (numberp (tramp-compat-file-attribute-link-number attr)))
+ (should (numberp (tramp-compat-file-attribute-user-id attr)))
+ (should (numberp (tramp-compat-file-attribute-group-id attr)))
+ (should
+ (stringp
+ (current-time-string
+ (tramp-compat-file-attribute-access-time attr))))
+ (should
+ (stringp
+ (current-time-string
+ (tramp-compat-file-attribute-modification-time attr))))
+ (should
+ (stringp
+ (current-time-string
+ (tramp-compat-file-attribute-status-change-time attr))))
+ (should (numberp (tramp-compat-file-attribute-size attr)))
+ (should (stringp (tramp-compat-file-attribute-modes attr)))
(setq attr (file-attributes tmp-name1 'string))
- (should (stringp (nth 2 attr))) ;; Uid.
- (should (stringp (nth 3 attr))) ;; Gid.
+ (should (stringp (tramp-compat-file-attribute-user-id attr)))
+ (should (stringp (tramp-compat-file-attribute-group-id attr)))
(tramp--test-ignore-make-symbolic-link-error
(should-error
(string-equal
(funcall
(if quoted #'tramp-compat-file-name-quote #'identity)
- (car attr))
+ (tramp-compat-file-attribute-type attr))
(file-remote-p (file-truename tmp-name1) 'localname)))
(delete-file tmp-name2))
(setq attr (file-attributes tmp-name2))
(should
(string-equal
- (car attr)
+ (tramp-compat-file-attribute-type attr)
(tramp-file-name-localname
(tramp-dissect-file-name tmp-name3))))
(delete-file tmp-name2))
(when (tramp--test-sh-p)
(should (file-ownership-preserved-p tmp-name1 'group)))
(setq attr (file-attributes tmp-name1))
- (should (eq (car attr) t)))
+ (should (eq (tramp-compat-file-attribute-type attr) t)))
;; Cleanup.
(ignore-errors (delete-directory tmp-name1))
(ignore-errors (delete-file tmp-name1))
(ignore-errors (delete-file tmp-name2))))))
+(defvar tramp--test-start-time nil
+ "Keep the start time of the current test, a float number.")
+
(defsubst tramp--test-file-attributes-equal-p (attr1 attr2)
"Check, whether file attributes ATTR1 and ATTR2 are equal.
They might differ only in time attributes or directory size."
(let ((attr1 (copy-sequence attr1))
(attr2 (copy-sequence attr2))
- (start-time
- (- (float-time
- (aref
- (ert--stats-test-start-times ert--current-run-stats)
- (ert--stats-test-pos ert--current-run-stats (ert-running-test))))
- 60)))
+ (start-time (- tramp--test-start-time 10)))
;; Access time.
(setcar (nthcdr 4 attr1) tramp-time-dont-know)
(setcar (nthcdr 4 attr2) tramp-time-dont-know)
;; we cannot compare, and we normalize the time stamps. If the
;; time value is newer than the test start time, normalize it,
;; because due to caching the time stamps could differ slightly (a
- ;; few seconds). We use a test start time minus 60 seconds, in
- ;; order to compensate a possible time offset on local and remote
- ;; machines.
- (when (or (tramp-compat-time-equal-p (nth 5 attr1) tramp-time-dont-know)
- (tramp-compat-time-equal-p (nth 5 attr2) tramp-time-dont-know))
+ ;; few seconds). We use a test start time minus 10 seconds, in
+ ;; order to compensate a possible timestamp resolution higher than
+ ;; a second on the remote machine.
+ (when (or (tramp-compat-time-equal-p
+ (tramp-compat-file-attribute-modification-time attr1)
+ tramp-time-dont-know)
+ (tramp-compat-time-equal-p
+ (tramp-compat-file-attribute-modification-time attr2)
+ tramp-time-dont-know))
(setcar (nthcdr 5 attr1) tramp-time-dont-know)
(setcar (nthcdr 5 attr2) tramp-time-dont-know))
- (when (< start-time (float-time (nth 5 attr1)))
+ (when (< start-time
+ (float-time (tramp-compat-file-attribute-modification-time attr1)))
(setcar (nthcdr 5 attr1) tramp-time-dont-know))
- (when (< start-time (float-time (nth 5 attr2)))
+ (when (< start-time
+ (float-time (tramp-compat-file-attribute-modification-time attr2)))
(setcar (nthcdr 5 attr2) tramp-time-dont-know))
;; Status change time. Dito.
- (when (or (tramp-compat-time-equal-p (nth 6 attr1) tramp-time-dont-know)
- (tramp-compat-time-equal-p (nth 6 attr2) tramp-time-dont-know))
+ (when (or (tramp-compat-time-equal-p
+ (tramp-compat-file-attribute-status-change-time attr1)
+ tramp-time-dont-know)
+ (tramp-compat-time-equal-p
+ (tramp-compat-file-attribute-status-change-time attr2)
+ tramp-time-dont-know))
(setcar (nthcdr 6 attr1) tramp-time-dont-know)
(setcar (nthcdr 6 attr2) tramp-time-dont-know))
- (when (< start-time (float-time (nth 6 attr1)))
+ (when
+ (< start-time
+ (float-time
+ (tramp-compat-file-attribute-status-change-time attr1)))
(setcar (nthcdr 6 attr1) tramp-time-dont-know))
- (when (< start-time (float-time (nth 6 attr2)))
+ (when
+ (< start-time
+ (float-time (tramp-compat-file-attribute-status-change-time attr2)))
(setcar (nthcdr 6 attr2) tramp-time-dont-know))
;; Size. Set it to 0 for directories, because it might have
;; changed. For example the upper directory "../".
- (when (eq (car attr1) t) (setcar (nthcdr 7 attr1) 0))
- (when (eq (car attr2) t) (setcar (nthcdr 7 attr2) 0))
+ (when (eq (tramp-compat-file-attribute-type attr1) t)
+ (setcar (nthcdr 7 attr1) 0))
+ (when (eq (tramp-compat-file-attribute-type attr2) t)
+ (setcar (nthcdr 7 attr2) 0))
;; The check.
(unless (equal attr1 attr2) (tramp--test-message "%S\n%S" attr1 attr2))
(equal attr1 attr2)))
(progn
(make-directory tmp-name1)
(should (file-directory-p tmp-name1))
+ (setq tramp--test-start-time
+ (float-time
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes tmp-name1))))
(make-directory tmp-name2)
(should (file-directory-p tmp-name2))
(write-region "foo" nil (expand-file-name "foo" tmp-name2))
(should (= (file-modes tmp-name) #o444))
(should-not (file-executable-p tmp-name))
;; A file is always writable for user "root".
- (unless (zerop (nth 2 (file-attributes tmp-name)))
+ (unless (zerop (tramp-compat-file-attribute-user-id
+ (file-attributes tmp-name)))
(should-not (file-writable-p tmp-name))))
;; Cleanup.
(progn
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
- (should (consp (nth 5 (file-attributes tmp-name1))))
+ (should (consp (tramp-compat-file-attribute-modification-time
+ (file-attributes tmp-name1))))
;; 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 (tramp-compat-time-equal-p
- (nth 5 (file-attributes tmp-name1)) tramp-time-dont-know)
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes tmp-name1))
+ tramp-time-dont-know)
(should
- (equal (nth 5 (file-attributes tmp-name1)) (seconds-to-time 1)))
+ (equal (tramp-compat-file-attribute-modification-time
+ (file-attributes tmp-name1))
+ (seconds-to-time 1)))
(write-region "bla" nil tmp-name2)
(should (file-exists-p tmp-name2))
(should (file-newer-than-file-p tmp-name2 tmp-name1))
(string-equal
(funcall
(if quoted #'tramp-compat-file-name-quote #'identity)
- (car (file-attributes file3)))
+ (tramp-compat-file-attribute-type (file-attributes file3)))
(file-remote-p (file-truename file1) 'localname)))
;; Check file contents.
(with-temp-buffer