From d3cd93dc4d917b6438117e82486f044e324a6088 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Wed, 6 Aug 2025 17:59:02 +0200 Subject: [PATCH] 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. --- lisp/net/tramp-adb.el | 4 ++-- lisp/net/tramp-smb.el | 11 ++++++++++- test/lisp/net/tramp-tests.el | 12 +++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index 2d240e8756b..5d6c053868b 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -573,9 +573,9 @@ Emacs dired can't find files." "touch -t %s %s %s") (format-time-string "%Y-%m-%dT%H:%M:%S.%NZ" time t) 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) - (format-time-string "%Y%m%d%H%M.%S" time t) + (format-time-string "%Y%m%d%H%M.%S" time) nofollow quoted-name))))) (defun tramp-adb-handle-copy-file diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 28364de83f1..fdda945f120 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -295,7 +295,7 @@ See `tramp-actions-before-shell' for more info.") (set-file-acl . tramp-smb-handle-set-file-acl) (set-file-modes . tramp-smb-handle-set-file-modes) (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) (shell-command . tramp-handle-shell-command) (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 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 ;; this, its original contents must be saved, and restored once ;; connection has been setup. diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 42426c76498..4438e0090d4 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -4552,7 +4552,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (skip-unless (tramp--test-enabled)) (skip-unless (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))) (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 (file-attributes tmp-name1)))) ;; Skip the test, if the remote handler is not able to set - ;; the correct time. - ;; Some remote machines cannot resolve seconds. So we use a minute. - (skip-unless (set-file-times tmp-name1 (seconds-to-time 60))) + ;; the correct time. Some remote machines cannot resolve + ;; seconds. tramp-adb.el needs at least a day. + (skip-unless + (set-file-times tmp-name1 (seconds-to-time (* 24 60 60)))) ;; Dumb remote shells without perl(1) or stat(1) are not ;; able to return the date correctly. They say "don't know". (unless (time-equal-p @@ -4577,7 +4579,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (should (time-equal-p (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. (should-error (set-file-times tmp-name2)