1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Add set-file-times implementation for Tramp smb method

* lisp/net/tramp-adb.el (tramp-adb-handle-set-file-times):
Don't use UTC in all cases.

* lisp/net/tramp-smb.el (tramp-smb-handle-set-file-times): New defun.
(tramp-smb-file-name-handler-alist): Use it.

* test/lisp/net/tramp-tests.el (tramp-test22-file-times): Adapt test.
This commit is contained in:
Michael Albinus 2025-08-06 17:59:02 +02:00
parent d950ca8ccd
commit d3cd93dc4d
3 changed files with 19 additions and 8 deletions

View file

@ -573,9 +573,9 @@ Emacs dired can't find files."
"touch -t %s %s %s") "touch -t %s %s %s")
(format-time-string "%Y-%m-%dT%H:%M:%S.%NZ" time t) (format-time-string "%Y-%m-%dT%H:%M:%S.%NZ" time t)
nofollow quoted-name (tramp-get-remote-null-device v) nofollow quoted-name (tramp-get-remote-null-device v)
(format-time-string "%Y-%m-%dT%H:%M:%S" time t) (format-time-string "%Y-%m-%dT%H:%M:%S" time)
nofollow quoted-name (tramp-get-remote-null-device v) nofollow quoted-name (tramp-get-remote-null-device v)
(format-time-string "%Y%m%d%H%M.%S" time t) (format-time-string "%Y%m%d%H%M.%S" time)
nofollow quoted-name))))) nofollow quoted-name)))))
(defun tramp-adb-handle-copy-file (defun tramp-adb-handle-copy-file

View file

@ -295,7 +295,7 @@ See `tramp-actions-before-shell' for more info.")
(set-file-acl . tramp-smb-handle-set-file-acl) (set-file-acl . tramp-smb-handle-set-file-acl)
(set-file-modes . tramp-smb-handle-set-file-modes) (set-file-modes . tramp-smb-handle-set-file-modes)
(set-file-selinux-context . ignore) (set-file-selinux-context . ignore)
(set-file-times . ignore) (set-file-times . tramp-smb-handle-set-file-times)
(set-visited-file-modtime . tramp-handle-set-visited-file-modtime) (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
(shell-command . tramp-handle-shell-command) (shell-command . tramp-handle-shell-command)
(start-file-process . tramp-smb-handle-start-file-process) (start-file-process . tramp-smb-handle-start-file-process)
@ -1534,6 +1534,15 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(tramp-error (tramp-error
v 'file-error "Error while changing file's mode %s" filename)))))) v 'file-error "Error while changing file's mode %s" filename))))))
(defun tramp-smb-handle-set-file-times (filename &optional time _flag)
"Like `set-file-times' for Tramp files."
(tramp-skeleton-set-file-modes-times-uid-gid filename
(tramp-smb-send-command
v (format
"utimes %s -1 -1 %s -1"
(tramp-smb-shell-quote-localname v)
(format-time-string "%Y:%m:%d-%H:%M:%S" (tramp-defined-time time))))))
;; We use BUFFER also as connection buffer during setup. Because of ;; We use BUFFER also as connection buffer during setup. Because of
;; this, its original contents must be saved, and restored once ;; this, its original contents must be saved, and restored once
;; connection has been setup. ;; connection has been setup.

View file

@ -4552,7 +4552,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(skip-unless (tramp--test-enabled)) (skip-unless (tramp--test-enabled))
(skip-unless (skip-unless
(or (tramp--test-adb-p) (tramp--test-gvfs-p) (or (tramp--test-adb-p) (tramp--test-gvfs-p)
(tramp--test-sh-p) (tramp--test-sudoedit-p))) (tramp--test-sh-p) (tramp--test-smb-p)
(tramp--test-sudoedit-p)))
(dolist (quoted (if (tramp--test-expensive-test-p) '(nil t) '(nil))) (dolist (quoted (if (tramp--test-expensive-test-p) '(nil t) '(nil)))
(let ((tmp-name1 (tramp--test-make-temp-name nil quoted)) (let ((tmp-name1 (tramp--test-make-temp-name nil quoted))
@ -4565,9 +4566,10 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(should (consp (file-attribute-modification-time (should (consp (file-attribute-modification-time
(file-attributes tmp-name1)))) (file-attributes tmp-name1))))
;; Skip the test, if the remote handler is not able to set ;; Skip the test, if the remote handler is not able to set
;; the correct time. ;; the correct time. Some remote machines cannot resolve
;; Some remote machines cannot resolve seconds. So we use a minute. ;; seconds. tramp-adb.el needs at least a day.
(skip-unless (set-file-times tmp-name1 (seconds-to-time 60))) (skip-unless
(set-file-times tmp-name1 (seconds-to-time (* 24 60 60))))
;; Dumb remote shells without perl(1) or stat(1) are not ;; Dumb remote shells without perl(1) or stat(1) are not
;; able to return the date correctly. They say "don't know". ;; able to return the date correctly. They say "don't know".
(unless (time-equal-p (unless (time-equal-p
@ -4577,7 +4579,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
(should (should
(time-equal-p (time-equal-p
(file-attribute-modification-time (file-attributes tmp-name1)) (file-attribute-modification-time (file-attributes tmp-name1))
(seconds-to-time 60))) (seconds-to-time (* 24 60 60))))
;; Setting the time for not existing files shall fail. ;; Setting the time for not existing files shall fail.
(should-error (should-error
(set-file-times tmp-name2) (set-file-times tmp-name2)