]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-sh.el
Some Tramp minor fixes, found during test campaign.
[gnu-emacs] / lisp / net / tramp-sh.el
index fc906b343cb5bf789aaa15548918a61ae6757e6d..4284fecf14f872314e4dfff848ff21ebe1e367d3 100644 (file)
@@ -60,6 +60,7 @@ files conditionalize this setup based on the TERM environment variable."
   :group 'tramp
   :type 'string)
 
+;;;###tramp-autoload
 (defconst tramp-color-escape-sequence-regexp "\e[[;0-9]+m"
   "Escape sequences produced by the \"ls\" command.")
 
@@ -1305,22 +1306,29 @@ of."
   "Like `set-file-times' for Tramp files."
   (if (tramp-tramp-file-p filename)
       (with-parsed-tramp-file-name filename nil
-       (tramp-flush-file-property v localname)
-       (let ((time (if (or (null time) (equal time '(0 0)))
-                       (current-time)
-                     time))
-             ;; With GNU Emacs, `format-time-string' has an optional
-             ;; parameter UNIVERSAL.  This is preferred, because we
-             ;; could handle the case when the remote host is located
-             ;; in a different time zone as the local host.
-             (utc (not (featurep 'xemacs))))
-         (tramp-send-command-and-check
-          v (format "%s touch -t %s %s"
-                    (if utc "env TZ=UTC" "")
-                    (if utc
-                        (format-time-string "%Y%m%d%H%M.%S" time t)
-                      (format-time-string "%Y%m%d%H%M.%S" time))
-                    (tramp-shell-quote-argument localname)))))
+       (when (tramp-get-remote-touch v)
+         (tramp-flush-file-property v localname)
+         (let ((time (if (or (null time) (equal time '(0 0)))
+                         (current-time)
+                       time))
+               ;; With GNU Emacs, `format-time-string' has an
+               ;; optional parameter UNIVERSAL.  This is preferred,
+               ;; because we could handle the case when the remote
+               ;; host is located in a different time zone as the
+               ;; local host.
+               (utc (not (featurep 'xemacs))))
+           (tramp-send-command-and-check
+            v (format
+               "%s %s %s %s"
+               (if utc "env TZ=UTC" "")
+               (tramp-get-remote-touch v)
+               (if (tramp-get-connection-property v "touch-t" nil)
+                   (format "-t %s"
+                           (if utc
+                               (format-time-string "%Y%m%d%H%M.%S" time t)
+                             (format-time-string "%Y%m%d%H%M.%S" time)))
+                 "")
+               (tramp-shell-quote-argument localname))))))
 
     ;; We handle also the local part, because in older Emacsen,
     ;; without `set-file-times', this function is an alias for this.
@@ -1562,39 +1570,45 @@ be non-negative integers."
 (defun tramp-sh-handle-directory-files-and-attributes
   (directory &optional full match nosort id-format)
   "Like `directory-files-and-attributes' for Tramp files."
-  (unless id-format (setq id-format 'integer))
-  (when (file-directory-p directory)
-    (setq directory (expand-file-name directory))
-    (let* ((temp
-           (copy-tree
-            (with-parsed-tramp-file-name directory nil
-              (with-tramp-file-property
-                  v localname
-                  (format "directory-files-and-attributes-%s" id-format)
-                (save-excursion
-                  (mapcar
-                   (lambda (x)
-                     (cons (car x)
-                           (tramp-convert-file-attributes v (cdr x))))
-                   (cond
-                    ((tramp-get-remote-stat v)
-                     (tramp-do-directory-files-and-attributes-with-stat
-                      v localname id-format))
-                    ((tramp-get-remote-perl v)
-                     (tramp-do-directory-files-and-attributes-with-perl
-                      v localname id-format)))))))))
-          result item)
-
-      (while temp
-       (setq item (pop temp))
-       (when (or (null match) (string-match match (car item)))
-         (when full
-           (setcar item (expand-file-name (car item) directory)))
-         (push item result)))
-
-      (if nosort
-         result
-       (sort result (lambda (x y) (string< (car x) (car y))))))))
+  (if (with-parsed-tramp-file-name directory nil
+       (not (or (tramp-get-remote-stat v) (tramp-get-remote-perl v))))
+      (tramp-handle-directory-files-and-attributes
+       directory full match nosort id-format)
+
+    ;; Do it directly.
+    (unless id-format (setq id-format 'integer))
+    (when (file-directory-p directory)
+      (setq directory (expand-file-name directory))
+      (let* ((temp
+             (copy-tree
+              (with-parsed-tramp-file-name directory nil
+                (with-tramp-file-property
+                    v localname
+                    (format "directory-files-and-attributes-%s" id-format)
+                  (save-excursion
+                    (mapcar
+                     (lambda (x)
+                       (cons (car x)
+                             (tramp-convert-file-attributes v (cdr x))))
+                     (cond
+                      ((tramp-get-remote-stat v)
+                       (tramp-do-directory-files-and-attributes-with-stat
+                        v localname id-format))
+                      ((tramp-get-remote-perl v)
+                       (tramp-do-directory-files-and-attributes-with-perl
+                        v localname id-format)))))))))
+            result item)
+
+       (while temp
+         (setq item (pop temp))
+         (when (or (null match) (string-match match (car item)))
+           (when full
+             (setcar item (expand-file-name (car item) directory)))
+           (push item result)))
+
+       (if nosort
+           result
+         (sort result (lambda (x y) (string< (car x) (car y)))))))))
 
 (defun tramp-do-directory-files-and-attributes-with-perl
   (vec localname &optional id-format)
@@ -4999,6 +5013,30 @@ Return ATTR."
     (tramp-message vec 5 "Finding a suitable `trash' command")
     (tramp-find-executable vec "trash" (tramp-get-remote-path vec))))
 
+(defun tramp-get-remote-touch (vec)
+  (with-tramp-connection-property vec "touch"
+    (tramp-message vec 5 "Finding a suitable `touch' command")
+    (let ((result (tramp-find-executable
+                  vec "touch" (tramp-get-remote-path vec)))
+         (tmpfile
+          (make-temp-name
+           (expand-file-name
+            tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))))
+      ;; Busyboxes do support the "-t" option only when they have been
+      ;; built with the DESKTOP config option.  Let's check it.
+      (when result
+       (tramp-set-connection-property
+        vec "touch-t"
+        (tramp-send-command-and-check
+         vec
+         (format
+          "%s -t %s %s"
+          result
+          (format-time-string "%Y%m%d%H%M.%S" (current-time))
+          (tramp-file-name-handler 'file-remote-p tmpfile 'localname))))
+       (delete-file tmpfile))
+      result)))
+
 (defun tramp-get-remote-gvfs-monitor-dir (vec)
   (with-tramp-connection-property vec "gvfs-monitor-dir"
     (tramp-message vec 5 "Finding a suitable `gvfs-monitor-dir' command")