]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp.el
; Remove superfluous merge from emacs-25
[gnu-emacs] / lisp / net / tramp.el
index e52f1958592336eba7ce358c0ffa8de6dcd5c4c2..4edca5a5998cd5f4e37372c932bf5318379a81e1 100644 (file)
@@ -120,8 +120,8 @@ This setting has precedence over `auto-save-file-name-transforms'."
                 (directory :tag "Auto save directory name")))
 
 (defcustom tramp-encoding-shell
-  (if (memq system-type '(windows-nt))
-      (getenv "COMSPEC")
+  (if (boundp 'w32-shell-name)
+      (symbol-value 'w32-shell-name)
     "/bin/sh")
   "Use this program for encoding and decoding commands on the local host.
 This shell is used to execute the encoding and decoding command on the
@@ -145,17 +145,14 @@ use for the remote host."
   :group 'tramp
   :type '(file :must-match t))
 
-(defcustom tramp-encoding-command-switch
-  (if (string-match "cmd\\.exe" tramp-encoding-shell)
-      "/c"
-    "-c")
+(defcustom tramp-encoding-command-switch (if (boundp 'w32-shell-name) "/c" "-c")
   "Use this switch together with `tramp-encoding-shell' for local commands.
 See the variable `tramp-encoding-shell' for more information."
   :group 'tramp
   :type 'string)
 
 (defcustom tramp-encoding-command-interactive
-  (unless (string-match "cmd\\.exe" tramp-encoding-shell) "-i")
+  (unless (boundp 'w32-shell-name) "-i")
   "Use this switch together with `tramp-encoding-shell' for interactive shells.
 See the variable `tramp-encoding-shell' for more information."
   :version "24.1"
@@ -1048,7 +1045,7 @@ entry does not exist, return nil."
         (replace-regexp-in-string "^tramp-" "" (symbol-name param))))
     (if (tramp-connection-property-p vec hash-entry)
        ;; We use the cached property.
-       (tramp-get-connection-property  vec hash-entry nil)
+       (tramp-get-connection-property vec hash-entry nil)
       ;; Use the static value from `tramp-methods'.
       (let ((methods-entry
             (assoc param (assoc (tramp-file-name-method vec) tramp-methods))))
@@ -1987,13 +1984,13 @@ Falls back to normal file name handler if no Tramp file name handler exists."
                (tramp-replace-environment-variables
                 (apply 'tramp-file-name-for-operation operation args)))
               (completion (tramp-completion-mode-p))
-              (foreign (tramp-find-foreign-file-name-handler filename)))
+              (foreign (tramp-find-foreign-file-name-handler filename))
+              result)
          (with-parsed-tramp-file-name filename nil
            ;; Call the backend function.
            (if foreign
                (tramp-condition-case-unless-debug err
-                   (let ((sf (symbol-function foreign))
-                         result)
+                   (let ((sf (symbol-function foreign)))
                      ;; Some packages set the default directory to a
                      ;; remote path, before respective Tramp packages
                      ;; are already loaded.  This results in
@@ -2057,8 +2054,13 @@ Falls back to normal file name handler if no Tramp file name handler exists."
                    ;; Propagate the error.
                    (t (signal (car err) (cdr err))))))
 
-             ;; Nothing to do for us.
-             (tramp-run-real-handler operation args)))))
+             ;; Nothing to do for us.  However, since we are in
+             ;; `tramp-mode', we must suppress the volume letter on
+             ;; MS Windows.
+             (setq result (tramp-run-real-handler operation args))
+             (if (stringp result)
+                 (tramp-drop-volume-letter result)
+               result)))))
 
     ;; When `tramp-mode' is not enabled, we don't do anything.
     (tramp-run-real-handler operation args)))
@@ -2624,17 +2626,18 @@ User is always nil."
    (tramp-parse-group
     (concat "^\\(" tramp-ipv6-regexp "\\|" tramp-host-regexp "\\)") 1 " \t"))
 
-;; For su-alike methods it would be desirable to return "root@localhost"
-;; as default.  Unfortunately, we have no information whether any user name
-;; has been typed already.  So we use `tramp-current-user' as indication,
-;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
 ;;;###tramp-autoload
 (defun tramp-parse-passwd (filename)
   "Return a list of (user host) tuples allowed to access.
 Host is always \"localhost\"."
-  (if (zerop (length tramp-current-user))
-      '(("root" nil))
-    (tramp-parse-file filename 'tramp-parse-passwd-group)))
+  (with-tramp-connection-property nil "parse-passwd"
+    (if (executable-find "getent")
+       (with-temp-buffer
+         (when (zerop (tramp-call-process nil "getent" nil t nil "passwd"))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-etc-group-group))))
+      (tramp-parse-file filename 'tramp-parse-passwd-group))))
 
 (defun tramp-parse-passwd-group ()
    "Return a (user host) tuple allowed to access.
@@ -2650,7 +2653,14 @@ Host is always \"localhost\"."
 (defun tramp-parse-etc-group (filename)
   "Return a list of (group host) tuples allowed to access.
 Host is always \"localhost\"."
-  (tramp-parse-file filename 'tramp-parse-etc-group-group))
+  (with-tramp-connection-property nil "parse-group"
+    (if (executable-find "getent")
+       (with-temp-buffer
+         (when (zerop (tramp-call-process nil "getent" nil t nil "group"))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-etc-group-group))))
+      (tramp-parse-file filename 'tramp-parse-etc-group-group))))
 
 (defun tramp-parse-etc-group-group ()
    "Return a (group host) tuple allowed to access.
@@ -2686,12 +2696,13 @@ User may be nil."
   "Return a list of (user host) tuples allowed to access.
 User is always nil."
   (if (memq system-type '(windows-nt))
-      (with-temp-buffer
-       (when (zerop (tramp-call-process
-                     nil "reg" nil t nil "query" registry-or-dirname))
-         (goto-char (point-min))
-         (loop while (not (eobp)) collect
-               (tramp-parse-putty-group registry-or-dirname))))
+      (with-tramp-connection-property nil "parse-putty"
+       (with-temp-buffer
+         (when (zerop (tramp-call-process
+                       nil "reg" nil t nil "query" registry-or-dirname))
+           (goto-char (point-min))
+           (loop while (not (eobp)) collect
+                 (tramp-parse-putty-group registry-or-dirname)))))
     ;; UNIX case.
     (tramp-parse-shostkeys-sknownhosts
      registry-or-dirname (concat "^\\(" tramp-host-regexp "\\)$"))))
@@ -2860,7 +2871,8 @@ User is always nil."
     (when (tramp-tramp-file-p filename)
       (let* ((v (tramp-dissect-file-name filename))
             (p (tramp-get-connection-process v))
-            (c (and p (processp p) (memq (process-status p) '(run open)))))
+            (c (and p (processp p) (memq (process-status p) '(run open))
+                    (tramp-get-connection-property p "connected" nil))))
        ;; We expand the file name only, if there is already a connection.
        (with-parsed-tramp-file-name
            (if c (expand-file-name filename) filename) nil
@@ -3732,6 +3744,26 @@ This is used internally by `tramp-file-mode-from-int'."
       (tramp-compat-funcall 'group-gid)
     (nth 3 (file-attributes "~/" id-format))))
 
+(defun tramp-get-local-locale (&optional vec)
+  ;; We use key nil for local connection properties.
+  (with-tramp-connection-property nil "locale"
+    (let ((candidates '("en_US.utf8" "C.utf8" "en_US.UTF-8"))
+         locale)
+      (with-temp-buffer
+       (unless (or (memq system-type '(windows-nt))
+                    (not (zerop (tramp-call-process
+                                 nil "locale" nil t nil "-a"))))
+         (while candidates
+           (goto-char (point-min))
+           (if (string-match (format "^%s\r?$" (regexp-quote (car candidates)))
+                             (buffer-string))
+               (setq locale (car candidates)
+                     candidates nil)
+             (setq candidates (cdr candidates))))))
+      ;; Return value.
+      (when vec (tramp-message vec 7 "locale %s" (or locale "C")))
+      (or locale "C"))))
+
 ;;;###tramp-autoload
 (defun tramp-check-cached-permissions (vec access)
   "Check `file-attributes' caches for VEC.