]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp-smb.el
* net/shr.el (shr-tag-img): Don't bug out on <img src=""> data.
[gnu-emacs] / lisp / net / tramp-smb.el
index 4270ad1671c772264cdadde01fc5c35a31d6025a..e322b6764a11d270acf45eb86e475f375a074ee9 100644 (file)
@@ -387,141 +387,152 @@ pass to the OPERATION."
        (throw 'tramp-action 'ok)))))
 
 (defun tramp-smb-handle-copy-directory
-  (dirname newname &optional keep-date parents _copy-contents)
+  (dirname newname &optional keep-date parents copy-contents)
   "Like `copy-directory' for Tramp files."
-  (setq dirname (expand-file-name dirname)
-       newname (expand-file-name newname))
-  (let ((t1 (tramp-tramp-file-p dirname))
-       (t2 (tramp-tramp-file-p newname)))
-    (with-parsed-tramp-file-name (if t1 dirname newname) nil
-      (with-tramp-progress-reporter
-         v 0 (format "Copying %s to %s" dirname newname)
-      (cond
-       ;; We must use a local temporary directory.
-       ((and t1 t2)
-       (let ((tmpdir
-              (make-temp-name
-               (expand-file-name
-                tramp-temp-name-prefix
-                (tramp-compat-temporary-file-directory)))))
-         (unwind-protect
-             (progn
-               (tramp-compat-copy-directory dirname tmpdir keep-date parents)
-               (tramp-compat-copy-directory tmpdir newname keep-date parents))
-           (tramp-compat-delete-directory tmpdir 'recursive))))
-
-       ;; We can copy recursively.
-       ((or t1 t2)
-       (when (and (file-directory-p newname)
-                  (not (string-equal (file-name-nondirectory dirname)
-                                     (file-name-nondirectory newname))))
-         (setq newname
-               (expand-file-name
-                (file-name-nondirectory dirname) newname))
-         (if t2 (setq v (tramp-dissect-file-name newname))))
-       (if (not (file-directory-p newname))
-           (make-directory newname parents))
-
-       (setq tramp-current-method (tramp-file-name-method v)
-             tramp-current-user (tramp-file-name-user v)
-             tramp-current-host (tramp-file-name-real-host v))
-
-       (let* ((real-user (tramp-file-name-real-user v))
-              (real-host (tramp-file-name-real-host v))
-              (domain    (tramp-file-name-domain v))
-              (port      (tramp-file-name-port v))
-              (share     (tramp-smb-get-share v))
-              (localname (file-name-as-directory
-                          (tramp-compat-replace-regexp-in-string
-                           "\\\\" "/" (tramp-smb-get-localname v))))
-              (tmpdir    (make-temp-name
-                          (expand-file-name
-                           tramp-temp-name-prefix
-                           (tramp-compat-temporary-file-directory))))
-              (args      (list tramp-smb-program
-                               (concat "//" real-host "/" share) "-E")))
-
-         (if (not (zerop (length real-user)))
-             (setq args (append args (list "-U" real-user)))
-           (setq args (append args (list "-N"))))
-
-         (when domain (setq args (append args (list "-W" domain))))
-         (when port   (setq args (append args (list "-p" port))))
-         (when tramp-smb-conf
-           (setq args (append args (list "-s" tramp-smb-conf))))
-         (setq args
-               (if t1
-                   ;; Source is remote.
-                   (append args
-                           (list "-D" (shell-quote-argument localname)
-                                 "-c" (shell-quote-argument "tar qc - *")
-                                 "|" "tar" "xfC" "-"
-                                 (shell-quote-argument tmpdir)))
-                 ;; Target is remote.
-                 (append (list "tar" "cfC" "-" (shell-quote-argument dirname)
-                               "." "|")
-                         args
-                         (list "-D" (shell-quote-argument localname)
-                               "-c" (shell-quote-argument "tar qx -")))))
-
-         (unwind-protect
-             (with-temp-buffer
-               ;; Set the transfer process properties.
-               (tramp-set-connection-property
-                v "process-name" (buffer-name (current-buffer)))
-               (tramp-set-connection-property
-                v "process-buffer" (current-buffer))
-
-               (when t1
-                 ;; The smbclient tar command creates always complete
-                 ;; paths.  We must emulate the directory structure,
-                 ;; and symlink to the real target.
-                 (make-directory
-                  (expand-file-name ".." (concat tmpdir localname)) 'parents)
-                 (make-symbolic-link
-                  newname (directory-file-name (concat tmpdir localname))))
-
-               ;; Use an asynchronous processes.  By this, password
-               ;; can be handled.
-               (let* ((default-directory tmpdir)
-                      (p (start-process-shell-command
-                          (tramp-get-connection-name v)
-                          (tramp-get-connection-buffer v)
-                          (mapconcat 'identity args " "))))
-
-                 (tramp-message
-                  v 6 "%s" (mapconcat 'identity (process-command p) " "))
-                 (tramp-set-connection-property p "vector" v)
-                 (tramp-compat-set-process-query-on-exit-flag p nil)
-                 (tramp-process-actions p v nil tramp-smb-actions-with-tar)
-
-                 (while (memq (process-status p) '(run open))
-                   (sit-for 0.1))
-                 (tramp-message v 6 "\n%s" (buffer-string))))
-
-           ;; 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))))
-
-       ;; Handle KEEP-DATE argument.
-       (when keep-date
-         (set-file-times newname (nth 5 (file-attributes dirname))))
-
-       ;; Set the mode.
-       (unless keep-date
-         (set-file-modes newname (tramp-default-file-modes dirname)))
-
-       ;; When newname did exist, we have wrong cached values.
-       (when t2
-         (with-parsed-tramp-file-name newname nil
-           (tramp-flush-file-property v (file-name-directory localname))
-           (tramp-flush-file-property v localname))))
-
-       ;; We must do it file-wise.
-       (t
-       (tramp-run-real-handler
-        'copy-directory (list dirname newname keep-date parents))))))))
+  (if copy-contents
+      ;; We must do it file-wise.
+      (tramp-run-real-handler
+       'copy-directory (list dirname newname keep-date parents copy-contents))
+
+    (setq dirname (expand-file-name dirname)
+         newname (expand-file-name newname))
+    (let ((t1 (tramp-tramp-file-p dirname))
+         (t2 (tramp-tramp-file-p newname)))
+      (with-parsed-tramp-file-name (if t1 dirname newname) nil
+       (with-tramp-progress-reporter
+           v 0 (format "Copying %s to %s" dirname newname)
+         (cond
+          ;; We must use a local temporary directory.
+          ((and t1 t2)
+           (let ((tmpdir
+                  (make-temp-name
+                   (expand-file-name
+                    tramp-temp-name-prefix
+                    (tramp-compat-temporary-file-directory)))))
+             (unwind-protect
+                 (progn
+                   (make-directory tmpdir)
+                   (tramp-compat-copy-directory
+                    dirname tmpdir keep-date 'parents)
+                   (tramp-compat-copy-directory
+                    (expand-file-name (file-name-nondirectory dirname) tmpdir)
+                    newname keep-date parents))
+               (tramp-compat-delete-directory tmpdir 'recursive))))
+
+          ;; We can copy recursively.
+          ((or t1 t2)
+           (when (and (file-directory-p newname)
+                      (not (string-equal (file-name-nondirectory dirname)
+                                         (file-name-nondirectory newname))))
+             (setq newname
+                   (expand-file-name
+                    (file-name-nondirectory dirname) newname))
+             (if t2 (setq v (tramp-dissect-file-name newname))))
+           (if (not (file-directory-p newname))
+               (make-directory newname parents))
+
+           (setq tramp-current-method (tramp-file-name-method v)
+                 tramp-current-user (tramp-file-name-user v)
+                 tramp-current-host (tramp-file-name-real-host v))
+
+           (let* ((real-user (tramp-file-name-real-user v))
+                  (real-host (tramp-file-name-real-host v))
+                  (domain    (tramp-file-name-domain v))
+                  (port      (tramp-file-name-port v))
+                  (share     (tramp-smb-get-share v))
+                  (localname (file-name-as-directory
+                              (tramp-compat-replace-regexp-in-string
+                               "\\\\" "/" (tramp-smb-get-localname v))))
+                  (tmpdir    (make-temp-name
+                              (expand-file-name
+                               tramp-temp-name-prefix
+                               (tramp-compat-temporary-file-directory))))
+                  (args      (list tramp-smb-program
+                                   (concat "//" real-host "/" share) "-E")))
+
+             (if (not (zerop (length real-user)))
+                 (setq args (append args (list "-U" real-user)))
+               (setq args (append args (list "-N"))))
+
+             (when domain (setq args (append args (list "-W" domain))))
+             (when port   (setq args (append args (list "-p" port))))
+             (when tramp-smb-conf
+               (setq args (append args (list "-s" tramp-smb-conf))))
+             (setq args
+                   (if t1
+                       ;; Source is remote.
+                       (append args
+                               (list "-D" (shell-quote-argument localname)
+                                     "-c" (shell-quote-argument "tar qc - *")
+                                     "|" "tar" "xfC" "-"
+                                     (shell-quote-argument tmpdir)))
+                     ;; Target is remote.
+                     (append (list "tar" "cfC" "-"
+                                   (shell-quote-argument dirname) "." "|")
+                             args
+                             (list "-D" (shell-quote-argument localname)
+                                   "-c" (shell-quote-argument "tar qx -")))))
+
+             (unwind-protect
+                 (with-temp-buffer
+                   ;; Set the transfer process properties.
+                   (tramp-set-connection-property
+                    v "process-name" (buffer-name (current-buffer)))
+                   (tramp-set-connection-property
+                    v "process-buffer" (current-buffer))
+
+                   (when t1
+                     ;; The smbclient tar command creates always
+                     ;; complete paths.  We must emulate the
+                     ;; directory structure, and symlink to the real
+                     ;; target.
+                     (make-directory
+                      (expand-file-name
+                       ".." (concat tmpdir localname)) 'parents)
+                     (make-symbolic-link
+                      newname (directory-file-name (concat tmpdir localname))))
+
+                   ;; Use an asynchronous processes.  By this,
+                   ;; password can be handled.
+                   (let* ((default-directory tmpdir)
+                          (p (start-process-shell-command
+                              (tramp-get-connection-name v)
+                              (tramp-get-connection-buffer v)
+                              (mapconcat 'identity args " "))))
+
+                     (tramp-message
+                      v 6 "%s" (mapconcat 'identity (process-command p) " "))
+                     (tramp-set-connection-property p "vector" v)
+                     (tramp-compat-set-process-query-on-exit-flag p nil)
+                     (tramp-process-actions p v nil tramp-smb-actions-with-tar)
+
+                     (while (memq (process-status p) '(run open))
+                       (sit-for 0.1))
+                     (tramp-message v 6 "\n%s" (buffer-string))))
+
+               ;; 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))))
+
+           ;; Handle KEEP-DATE argument.
+           (when keep-date
+             (set-file-times newname (nth 5 (file-attributes dirname))))
+
+           ;; Set the mode.
+           (unless keep-date
+             (set-file-modes newname (tramp-default-file-modes dirname)))
+
+           ;; When newname did exist, we have wrong cached values.
+           (when t2
+             (with-parsed-tramp-file-name newname nil
+               (tramp-flush-file-property v (file-name-directory localname))
+               (tramp-flush-file-property v localname))))
+
+          ;; We must do it file-wise.
+          (t
+           (tramp-run-real-handler
+            'copy-directory (list dirname newname keep-date parents)))))))))
 
 (defun tramp-smb-handle-copy-file
   (filename newname &optional ok-if-already-exists keep-date
@@ -631,7 +642,8 @@ 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))))
+                       (file-name-all-completions "" directory)))
+       res)
     ;; Discriminate with regexp.
     (when match
       (setq result
@@ -642,12 +654,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
     (when full
       (setq result
            (mapcar
-            (lambda (x) (expand-file-name x directory))
+            (lambda (x) (format "%s/%s" directory x))
             result)))
     ;; Sort them if necessary.
     (unless nosort (setq result (sort result 'string-lessp)))
-    ;; That's it.
-    result))
+    ;; Remove double entries.
+    (dolist (elt result res)
+      (add-to-list 'res elt 'append))))
 
 (defun tramp-smb-handle-expand-file-name (name &optional dir)
   "Like `expand-file-name' for Tramp files."
@@ -915,6 +928,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
   (filename switches &optional wildcard full-directory-p)
   "Like `insert-directory' for Tramp files."
   (setq filename (expand-file-name filename))
+  (unless switches (setq switches ""))
   (if full-directory-p
       ;; Called from `dired-add-entry'.
       (setq filename (file-name-as-directory filename))
@@ -1432,9 +1446,6 @@ errors for shares like \"C$/\", which are common in Microsoft Windows."
   "Like `write-region' for Tramp files."
   (setq filename (expand-file-name filename))
   (with-parsed-tramp-file-name filename nil
-    (unless (eq append nil)
-      (tramp-error
-        v 'file-error "Cannot append to file using Tramp (`%s')" filename))
     ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
     (when (and (not (featurep 'xemacs))
               confirm (file-exists-p filename))
@@ -1447,6 +1458,8 @@ errors for shares like \"C$/\", which are common in Microsoft Windows."
     (tramp-flush-file-property v localname)
     (let ((curbuf (current-buffer))
          (tmpfile (tramp-compat-make-temp-file filename)))
+      (when (and append (file-exists-p filename))
+       (copy-file filename tmpfile 'ok))
       ;; We say `no-message' here because we don't want the visited file
       ;; modtime data to be clobbered from the temp file.  We call
       ;; `set-visited-file-modtime' ourselves later on.
@@ -1718,7 +1731,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)."
   ;; When we are not logged in yet, we return nil.
   (if (and (tramp-smb-get-share vec)
           (let ((p (tramp-get-connection-process vec)))
-            p (processp p) (memq (process-status p) '(run open))))
+            (and p (processp p) (memq (process-status p) '(run open)))))
       (with-tramp-connection-property
          (tramp-get-connection-process vec) "stat-capability"
        (tramp-smb-send-command vec "stat \"/\""))))
@@ -1901,9 +1914,9 @@ If ARGUMENT is non-nil, use it as argument for
                            (search-forward-regexp
                             tramp-smb-wrong-passwd-regexp nil t))
                       ;; Disable `auth-source' and `password-cache'.
-                      (tramp-message
-                       vec 3 "Retry connection with new password")
                       (let (auth-sources)
+                        (tramp-message
+                         vec 3 "Retry connection with new password")
                         (tramp-cleanup-connection vec t)
                         (tramp-smb-maybe-open-connection vec argument))
                     ;; Propagate the error.