]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-smb.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / net / tramp-smb.el
index e322b6764a11d270acf45eb86e475f375a074ee9..e957fdfd612d8bbe5ae7d5d0eea15ff741f1eb5c 100644 (file)
@@ -1,6 +1,6 @@
 ;;; tramp-smb.el --- Tramp access functions for SMB servers
 
-;; Copyright (C) 2002-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2016 Free Software Foundation, Inc.
 
 ;; Author: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, processes
     tramp-smb-method
     '((tramp-parse-netrc "~/.netrc"))))
 
+;;;###tramp-autoload
 (defcustom tramp-smb-program "smbclient"
   "Name of SMB client to run."
   :group 'tramp
   :type 'string)
 
+;;;###tramp-autoload
 (defcustom tramp-smb-acl-program "smbcacls"
   "Name of SMB acls to run."
   :group 'tramp
   :type 'string
   :version "24.4")
 
+;;;###tramp-autoload
 (defcustom tramp-smb-conf "/dev/null"
   "Path of the smb.conf file.
 If it is nil, no smb.conf will be added to the `tramp-smb-program'
@@ -229,10 +232,10 @@ See `tramp-actions-before-shell' for more info.")
     (file-acl . tramp-smb-handle-file-acl)
     (file-attributes . tramp-smb-handle-file-attributes)
     (file-directory-p .  tramp-smb-handle-file-directory-p)
-    ;; `file-equal-p' performed by default handler.
+    (file-file-equal-p . tramp-handle-file-equal-p)
     (file-executable-p . tramp-handle-file-exists-p)
     (file-exists-p . tramp-handle-file-exists-p)
-    ;; `file-in-directory-p' performed by default handler.
+    (file-in-directory-p . tramp-handle-file-in-directory-p)
     (file-local-copy . tramp-smb-handle-file-local-copy)
     (file-modes . tramp-handle-file-modes)
     (file-name-all-completions . tramp-smb-handle-file-name-all-completions)
@@ -244,6 +247,7 @@ See `tramp-actions-before-shell' for more info.")
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-notify-add-watch . tramp-handle-file-notify-add-watch)
     (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
+    (file-notify-valid-p . tramp-handle-file-notify-valid-p)
     (file-ownership-preserved-p . ignore)
     (file-readable-p . tramp-handle-file-exists-p)
     (file-regular-p . tramp-handle-file-regular-p)
@@ -280,6 +284,7 @@ See `tramp-actions-before-shell' for more info.")
 Operations not mentioned here will be handled by the default Emacs primitives.")
 
 ;; Options for remote processes via winexe.
+;;;###tramp-autoload
 (defcustom tramp-smb-winexe-program "winexe"
   "Name of winexe client to run.
 If it isn't found in the local $PATH, the absolute path of winexe
@@ -288,6 +293,7 @@ shall be given.  This is needed for remote processes."
   :type 'string
   :version "24.3")
 
+;;;###tramp-autoload
 (defcustom tramp-smb-winexe-shell-command "powershell.exe"
   "Shell to be used for processes on remote machines.
 This must be Powershell V2 compatible."
@@ -295,6 +301,7 @@ This must be Powershell V2 compatible."
   :type 'string
   :version "24.3")
 
+;;;###tramp-autoload
 (defcustom tramp-smb-winexe-shell-command-switch "-file -"
   "Command switch used together with `tramp-smb-winexe-shell-command'.
 This can be used to disable echo etc."
@@ -447,8 +454,7 @@ pass to the OPERATION."
                               (expand-file-name
                                tramp-temp-name-prefix
                                (tramp-compat-temporary-file-directory))))
-                  (args      (list tramp-smb-program
-                                   (concat "//" real-host "/" share) "-E")))
+                  (args      (list (concat "//" real-host "/" share) "-E")))
 
              (if (not (zerop (length real-user)))
                  (setq args (append args (list "-U" real-user)))
@@ -495,10 +501,11 @@ pass to the OPERATION."
                    ;; Use an asynchronous processes.  By this,
                    ;; password can be handled.
                    (let* ((default-directory tmpdir)
-                          (p (start-process-shell-command
+                          (p (apply
+                              'start-process
                               (tramp-get-connection-name v)
                               (tramp-get-connection-buffer v)
-                              (mapconcat 'identity args " "))))
+                              tramp-smb-program args)))
 
                      (tramp-message
                       v 6 "%s" (mapconcat 'identity (process-command p) " "))
@@ -513,7 +520,7 @@ pass to the OPERATION."
                ;; Reset the transfer process properties.
                (tramp-set-connection-property v "process-name" nil)
                (tramp-set-connection-property v "process-buffer" nil)
-               (when t1 (delete-directory tmpdir 'recurse))))
+               (when t1 (tramp-compat-delete-directory tmpdir 'recurse))))
 
            ;; Handle KEEP-DATE argument.
            (when keep-date
@@ -642,8 +649,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
   (directory &optional full match nosort)
   "Like `directory-files' for Tramp files."
   (let ((result (mapcar 'directory-file-name
-                       (file-name-all-completions "" directory)))
-       res)
+                       (file-name-all-completions "" directory))))
     ;; Discriminate with regexp.
     (when match
       (setq result
@@ -659,8 +665,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
     ;; Sort them if necessary.
     (unless nosort (setq result (sort result 'string-lessp)))
     ;; Remove double entries.
-    (dolist (elt result res)
-      (add-to-list 'res elt 'append))))
+    (tramp-compat-delete-dups result)))
 
 (defun tramp-smb-handle-expand-file-name (name &optional dir)
   "Like `expand-file-name' for Tramp files."
@@ -929,101 +934,108 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
   "Like `insert-directory' for Tramp files."
   (setq filename (expand-file-name filename))
   (unless switches (setq switches ""))
+  ;; Mark trailing "/".
+  (when (and (zerop (length (file-name-nondirectory filename)))
+            (not full-directory-p))
+    (setq switches (concat switches "F")))
   (if full-directory-p
       ;; Called from `dired-add-entry'.
       (setq filename (file-name-as-directory filename))
     (setq filename (directory-file-name filename)))
   (with-parsed-tramp-file-name filename nil
-    (save-match-data
-      (let ((base (file-name-nondirectory filename))
-           ;; We should not destroy the cache entry.
-           (entries (copy-sequence
-                     (tramp-smb-get-file-entries
-                      (file-name-directory filename)))))
-
-       (when wildcard
-         (string-match "\\." base)
-         (setq base (replace-match "\\\\." nil nil base))
-         (string-match "\\*" base)
-         (setq base (replace-match ".*" nil nil base))
-         (string-match "\\?" base)
-         (setq base (replace-match ".?" nil nil base)))
-
-       ;; Filter entries.
-       (setq entries
-             (delq
-              nil
-              (if (or wildcard (zerop (length base)))
-                  ;; Check for matching entries.
-                  (mapcar
-                   (lambda (x)
-                     (when (string-match
-                            (format "^%s" base) (nth 0 x))
-                       x))
-                   entries)
-                ;; We just need the only and only entry FILENAME.
-                (list (assoc base entries)))))
-
-       ;; Sort entries.
-       (setq entries
-             (sort
-              entries
-              (lambda (x y)
-                (if (string-match "t" switches)
-                    ;; Sort by date.
-                    (tramp-time-less-p (nth 3 y) (nth 3 x))
-                  ;; Sort by name.
-                  (string-lessp (nth 0 x) (nth 0 y))))))
-
-       ;; Handle "-F" switch.
-       (when (string-match "F" switches)
+    (with-tramp-progress-reporter v 0 (format "Opening directory %s" filename)
+      (save-match-data
+       (let ((base (file-name-nondirectory filename))
+             ;; We should not destroy the cache entry.
+             (entries (copy-sequence
+                       (tramp-smb-get-file-entries
+                        (file-name-directory filename)))))
+
+         (when wildcard
+           (string-match "\\." base)
+           (setq base (replace-match "\\\\." nil nil base))
+           (string-match "\\*" base)
+           (setq base (replace-match ".*" nil nil base))
+           (string-match "\\?" base)
+           (setq base (replace-match ".?" nil nil base)))
+
+         ;; Filter entries.
+         (setq entries
+               (delq
+                nil
+                (if (or wildcard (zerop (length base)))
+                    ;; Check for matching entries.
+                    (mapcar
+                     (lambda (x)
+                       (when (string-match
+                              (format "^%s" base) (nth 0 x))
+                         x))
+                     entries)
+                  ;; We just need the only and only entry FILENAME.
+                  (list (assoc base entries)))))
+
+         ;; Sort entries.
+         (setq entries
+               (sort
+                entries
+                (lambda (x y)
+                  (if (string-match "t" switches)
+                      ;; Sort by date.
+                      (time-less-p (nth 3 y) (nth 3 x))
+                    ;; Sort by name.
+                    (string-lessp (nth 0 x) (nth 0 y))))))
+
+         ;; Handle "-F" switch.
+         (when (string-match "F" switches)
+           (mapc
+            (lambda (x)
+              (when (not (zerop (length (car x))))
+                (cond
+                 ((char-equal ?d (string-to-char (nth 1 x)))
+                  (setcar x (concat (car x) "/")))
+                 ((char-equal ?x (string-to-char (nth 1 x)))
+                  (setcar x (concat (car x) "*"))))))
+            entries))
+
+         ;; Print entries.
          (mapc
           (lambda (x)
-            (when (not (zerop (length (car x))))
-              (cond
-               ((char-equal ?d (string-to-char (nth 1 x)))
-                (setcar x (concat (car x) "/")))
-               ((char-equal ?x (string-to-char (nth 1 x)))
-                (setcar x (concat (car x) "*"))))))
-          entries))
-
-       ;; Print entries.
-       (mapc
-        (lambda (x)
-          (when (not (zerop (length (nth 0 x))))
-            (let ((attr
-                   (when (tramp-smb-get-stat-capability v)
-                     (ignore-errors
-                       (file-attributes filename 'string)))))
-              (insert
-               (format
-                "%10s %3d %-8s %-8s %8s %s "
-                (or (nth 8 attr) (nth 1 x)) ; mode
-                (or (nth 1 attr) 1) ; inode
-                (or (nth 2 attr) "nobody") ; uid
-                (or (nth 3 attr) "nogroup") ; gid
-                (or (nth 7 attr) (nth 2 x)) ; size
-                (format-time-string
-                 (if (tramp-time-less-p
-                      (tramp-time-subtract (current-time) (nth 3 x))
-                      tramp-half-a-year)
-                     "%b %e %R"
-                   "%b %e  %Y")
-                 (nth 3 x)))) ; date
+            (when (not (zerop (length (nth 0 x))))
+              (when (string-match "l" switches)
+                (let ((attr
+                       (when (tramp-smb-get-stat-capability v)
+                         (ignore-errors
+                           (file-attributes filename 'string)))))
+                  (insert
+                   (format
+                    "%10s %3d %-8s %-8s %8s %s "
+                    (or (nth 8 attr) (nth 1 x)) ; mode
+                    (or (nth 1 attr) 1) ; inode
+                    (or (nth 2 attr) "nobody") ; uid
+                    (or (nth 3 attr) "nogroup") ; gid
+                    (or (nth 7 attr) (nth 2 x)) ; size
+                    (format-time-string
+                     (if (time-less-p (time-subtract (current-time) (nth 3 x))
+                          tramp-half-a-year)
+                         "%b %e %R"
+                       "%b %e  %Y")
+                     (nth 3 x)))))) ; date
+
               ;; We mark the file name.  The inserted name could be
-              ;; from somewhere else, so we use the relative file
-              ;; name of `default-directory'.
+              ;; from somewhere else, so we use the relative file name
+              ;; of `default-directory'.
               (let ((start (point)))
                 (insert
                  (format
                   "%s\n"
                   (file-relative-name
                    (expand-file-name
-                    (nth 0 x) (file-name-directory filename)))))
+                    (nth 0 x) (file-name-directory filename))
+                   (when full-directory-p (file-name-directory filename)))))
                 (put-text-property start (1- (point)) 'dired-filename t))
               (forward-line)
-              (beginning-of-line))))
-        entries)))))
+              (beginning-of-line)))
+          entries))))))
 
 (defun tramp-smb-handle-make-directory (dir &optional parents)
   "Like `make-directory' for Tramp files."
@@ -1217,8 +1229,8 @@ target of the symlink differ."
        (error
         (setq ret 1)))
 
-      ;; We should show the output anyway.
-      (when (and outbuf display) (display-buffer outbuf))
+      ;; We should redisplay the output.
+      (when (and display outbuf (get-buffer-window outbuf t)) (redisplay))
 
       ;; Cleanup.  We remove all file cache values for the connection,
       ;; because the remote process could have changed them.
@@ -1229,9 +1241,9 @@ target of the symlink differ."
        (kill-buffer (tramp-get-connection-property v "process-buffer" nil)))
 
       ;; `process-file-side-effects' has been introduced with GNU
-      ;; Emacs 23.2.  If set to `nil', no remote file will be changed
+      ;; Emacs 23.2.  If set to nil, no remote file will be changed
       ;; by `program'.  If it doesn't exist, we assume its default
-      ;; value `t'.
+      ;; value t.
       (unless (and (boundp 'process-file-side-effects)
                   (not (symbol-value 'process-file-side-effects)))
        (tramp-flush-directory-property v ""))
@@ -1270,6 +1282,8 @@ target of the symlink differ."
 
            ;; We must also flush the cache of the directory, because
            ;; `file-attributes' reads the values from there.
+           (tramp-flush-file-property v1 (file-name-directory v1-localname))
+           (tramp-flush-file-property v1 v1-localname)
            (tramp-flush-file-property v2 (file-name-directory v2-localname))
            (tramp-flush-file-property v2 v2-localname)
            (unless (tramp-smb-get-share v2)
@@ -1342,7 +1356,7 @@ target of the symlink differ."
                ;; Use an asynchronous processes.  By this, password can
                ;; be handled.
                (let ((p (apply
-                         'start-process-shell-command
+                         'start-process
                          (tramp-get-connection-name v)
                          (tramp-get-connection-buffer v)
                          tramp-smb-acl-program args)))