diff options
| author | Michael Albinus | 2009-07-28 20:36:57 +0000 |
|---|---|---|
| committer | Michael Albinus | 2009-07-28 20:36:57 +0000 |
| commit | 905fb90eb1149bca3a8ff21da413c7dd112273c2 (patch) | |
| tree | ad3fc2d4c0b3467d601c64e962143debb2e1a433 | |
| parent | e8d2d3fb19902626992a00b09f56cadb880ff1e0 (diff) | |
| download | emacs-905fb90eb1149bca3a8ff21da413c7dd112273c2.tar.gz emacs-905fb90eb1149bca3a8ff21da413c7dd112273c2.zip | |
* net/tramp.el (tramp-do-copy-or-rename-file): Add messages.
Simplify check for out-of-band methods.
(tramp-do-copy-or-rename-file-out-of-band): Allow both files to be
remote. Remove messages which are in `tramp-do-copy-or-rename-file'.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 205 |
2 files changed, 116 insertions, 96 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e295e41b026..42d77aff5fd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2009-07-28 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/tramp.el (tramp-do-copy-or-rename-file): Add messages. | ||
| 4 | Simplify check for out-of-band methods. | ||
| 5 | (tramp-do-copy-or-rename-file-out-of-band): Allow both files to be | ||
| 6 | remote. Remove messages which are in `tramp-do-copy-or-rename-file'. | ||
| 7 | |||
| 1 | 2009-07-28 Dan Nicolaescu <dann@ics.uci.edu> | 8 | 2009-07-28 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 9 | ||
| 3 | * vc-git.el (vc-git-checkin): Fix typo. | 10 | * vc-git.el (vc-git-checkin): Fix typo. |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 6de2346b766..76cd679d774 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -3118,6 +3118,9 @@ and `rename'. FILENAME and NEWNAME must be absolute file names." | |||
| 3118 | (tramp-error | 3118 | (tramp-error |
| 3119 | v 'file-already-exists "File %s already exists" newname))) | 3119 | v 'file-already-exists "File %s already exists" newname))) |
| 3120 | 3120 | ||
| 3121 | (with-parsed-tramp-file-name (if t1 filename newname) nil | ||
| 3122 | (tramp-message v 0 "Transferring %s to %s..." filename newname)) | ||
| 3123 | |||
| 3121 | (prog1 | 3124 | (prog1 |
| 3122 | (cond | 3125 | (cond |
| 3123 | ;; Both are Tramp files. | 3126 | ;; Both are Tramp files. |
| @@ -3133,13 +3136,8 @@ and `rename'. FILENAME and NEWNAME must be absolute file names." | |||
| 3133 | op filename newname | 3136 | op filename newname |
| 3134 | ok-if-already-exists keep-date preserve-uid-gid)) | 3137 | ok-if-already-exists keep-date preserve-uid-gid)) |
| 3135 | 3138 | ||
| 3136 | ;; If both source and target are Tramp files, | 3139 | ;; Try out-of-band operation. |
| 3137 | ;; both are using the same copy-program, then we | 3140 | ((and (tramp-method-out-of-band-p v1) |
| 3138 | ;; can invoke rcp directly. Note that | ||
| 3139 | ;; default-directory should point to a local | ||
| 3140 | ;; directory if we want to invoke rcp. | ||
| 3141 | ((and (equal v1-method v2-method) | ||
| 3142 | (tramp-method-out-of-band-p v1) | ||
| 3143 | (> (nth 7 (file-attributes filename)) | 3141 | (> (nth 7 (file-attributes filename)) |
| 3144 | tramp-copy-size-limit)) | 3142 | tramp-copy-size-limit)) |
| 3145 | (tramp-do-copy-or-rename-file-out-of-band | 3143 | (tramp-do-copy-or-rename-file-out-of-band |
| @@ -3192,7 +3190,10 @@ and `rename'. FILENAME and NEWNAME must be absolute file names." | |||
| 3192 | ;; When newname did exist, we have wrong cached values. | 3190 | ;; When newname did exist, we have wrong cached values. |
| 3193 | (when t2 | 3191 | (when t2 |
| 3194 | (with-parsed-tramp-file-name newname nil | 3192 | (with-parsed-tramp-file-name newname nil |
| 3195 | (tramp-flush-file-property v localname)))))) | 3193 | (tramp-flush-file-property v localname))) |
| 3194 | |||
| 3195 | (with-parsed-tramp-file-name (if t1 filename newname) nil | ||
| 3196 | (tramp-message v 0 "Transferring %s to %s...done" filename newname))))) | ||
| 3196 | 3197 | ||
| 3197 | (defun tramp-do-copy-or-rename-file-via-buffer (op filename newname keep-date) | 3198 | (defun tramp-do-copy-or-rename-file-via-buffer (op filename newname keep-date) |
| 3198 | "Use an Emacs buffer to copy or rename a file. | 3199 | "Use an Emacs buffer to copy or rename a file. |
| @@ -3376,106 +3377,117 @@ the uid and gid from FILENAME." | |||
| 3376 | 3377 | ||
| 3377 | (defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date) | 3378 | (defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date) |
| 3378 | "Invoke rcp program to copy. | 3379 | "Invoke rcp program to copy. |
| 3379 | One of FILENAME and NEWNAME must be a Tramp name, the other must | 3380 | The method used must be an out-of-band method." |
| 3380 | be a local filename. The method used must be an out-of-band method." | ||
| 3381 | (let ((t1 (tramp-tramp-file-p filename)) | 3381 | (let ((t1 (tramp-tramp-file-p filename)) |
| 3382 | (t2 (tramp-tramp-file-p newname)) | 3382 | (t2 (tramp-tramp-file-p newname)) |
| 3383 | copy-program copy-args copy-keep-date port spec | 3383 | copy-program copy-args copy-keep-date port spec |
| 3384 | source target) | 3384 | source target) |
| 3385 | 3385 | ||
| 3386 | (with-parsed-tramp-file-name (if t1 filename newname) nil | 3386 | (with-parsed-tramp-file-name (if t1 filename newname) nil |
| 3387 | (if (and t1 t2) | ||
| 3387 | 3388 | ||
| 3388 | ;; Expand hops. Might be necessary for gateway methods. | 3389 | ;; Both are Tramp files. We shall optimize it, when the |
| 3389 | (setq v (car (tramp-compute-multi-hops v))) | 3390 | ;; methods for filename and newname are the same. |
| 3390 | (aset v 3 localname) | 3391 | (let ((tmpfile (tramp-compat-make-temp-file localname))) |
| 3391 | 3392 | (unwind-protect | |
| 3392 | ;; Check which ones of source and target are Tramp files. | 3393 | (progn |
| 3393 | (setq source (if t1 (tramp-make-copy-program-file-name v) filename) | 3394 | (tramp-do-copy-or-rename-file-out-of-band |
| 3394 | target (if t2 (tramp-make-copy-program-file-name v) newname)) | 3395 | op filename tmpfile keep-date) |
| 3395 | 3396 | (tramp-do-copy-or-rename-file-out-of-band | |
| 3396 | ;; Check for port number. Until now, there's no need for handling | 3397 | 'rename tmpfile newname keep-date)) |
| 3397 | ;; like method, user, host. | 3398 | ;; Save exit. |
| 3398 | (setq host (tramp-file-name-real-host v) | 3399 | (condition-case nil |
| 3399 | port (tramp-file-name-port v) | 3400 | (delete-file tmpfile) |
| 3400 | port (or (and port (number-to-string port)) "")) | 3401 | (error)))) |
| 3401 | 3402 | ||
| 3402 | ;; Compose copy command. | 3403 | ;; Expand hops. Might be necessary for gateway methods. |
| 3403 | (setq spec `((?h . ,host) (?u . ,user) (?p . ,port) | 3404 | (setq v (car (tramp-compute-multi-hops v))) |
| 3404 | (?t . ,(tramp-get-connection-property | 3405 | (aset v 3 localname) |
| 3405 | (tramp-get-connection-process v) "temp-file" "")) | 3406 | |
| 3406 | (?k . ,(if keep-date " " ""))) | 3407 | ;; Check which ones of source and target are Tramp files. |
| 3407 | copy-program (tramp-get-method-parameter | 3408 | (setq source (if t1 (tramp-make-copy-program-file-name v) filename) |
| 3408 | method 'tramp-copy-program) | 3409 | target (if t2 (tramp-make-copy-program-file-name v) newname)) |
| 3409 | copy-keep-date (tramp-get-method-parameter | 3410 | |
| 3410 | method 'tramp-copy-keep-date) | 3411 | ;; Check for port number. Until now, there's no need for handling |
| 3411 | copy-args | 3412 | ;; like method, user, host. |
| 3412 | (delq | 3413 | (setq host (tramp-file-name-real-host v) |
| 3413 | nil | 3414 | port (tramp-file-name-port v) |
| 3414 | (mapcar | 3415 | port (or (and port (number-to-string port)) "")) |
| 3415 | '(lambda (x) | 3416 | |
| 3416 | (setq | 3417 | ;; Compose copy command. |
| 3417 | ;; " " is indication for keep-date argument. | 3418 | (setq spec `((?h . ,host) (?u . ,user) (?p . ,port) |
| 3418 | x (delete " " (mapcar '(lambda (y) (format-spec y spec)) x))) | 3419 | (?t . ,(tramp-get-connection-property |
| 3419 | (unless (member "" x) (mapconcat 'identity x " "))) | 3420 | (tramp-get-connection-process v) "temp-file" "")) |
| 3420 | (tramp-get-method-parameter method 'tramp-copy-args)))) | 3421 | (?k . ,(if keep-date " " ""))) |
| 3421 | 3422 | copy-program (tramp-get-method-parameter | |
| 3422 | ;; Check for program. | 3423 | method 'tramp-copy-program) |
| 3423 | (when (and (fboundp 'executable-find) | 3424 | copy-keep-date (tramp-get-method-parameter |
| 3424 | (not (let ((default-directory | 3425 | method 'tramp-copy-keep-date) |
| 3425 | (tramp-compat-temporary-file-directory))) | 3426 | copy-args |
| 3426 | (executable-find copy-program)))) | 3427 | (delq |
| 3427 | (tramp-error | 3428 | nil |
| 3428 | v 'file-error "Cannot find copy program: %s" copy-program)) | 3429 | (mapcar |
| 3429 | 3430 | '(lambda (x) | |
| 3430 | (tramp-message v 0 "Transferring %s to %s..." filename newname) | 3431 | (setq |
| 3431 | 3432 | x | |
| 3432 | (unwind-protect | 3433 | ;; " " is indication for keep-date argument. |
| 3433 | (with-temp-buffer | 3434 | (delete " " (mapcar '(lambda (y) (format-spec y spec)) x))) |
| 3434 | ;; The default directory must be remote. | 3435 | (unless (member "" x) (mapconcat 'identity x " "))) |
| 3435 | (let ((default-directory | 3436 | (tramp-get-method-parameter method 'tramp-copy-args)))) |
| 3436 | (file-name-directory (if t1 filename newname)))) | 3437 | |
| 3437 | ;; Set the transfer process properties. | 3438 | ;; Check for program. |
| 3438 | (tramp-set-connection-property | 3439 | (when (and (fboundp 'executable-find) |
| 3439 | v "process-name" (buffer-name (current-buffer))) | 3440 | (not (let ((default-directory |
| 3440 | (tramp-set-connection-property | 3441 | (tramp-compat-temporary-file-directory))) |
| 3441 | v "process-buffer" (current-buffer)) | 3442 | (executable-find copy-program)))) |
| 3442 | 3443 | (tramp-error | |
| 3443 | ;; Use an asynchronous process. By this, password can | 3444 | v 'file-error "Cannot find copy program: %s" copy-program)) |
| 3444 | ;; be handled. The default directory must be local, in | ||
| 3445 | ;; order to apply the correct `copy-program'. We don't | ||
| 3446 | ;; set a timeout, because the copying of large files can | ||
| 3447 | ;; last longer than 60 secs. | ||
| 3448 | (let ((p (let ((default-directory | ||
| 3449 | (tramp-compat-temporary-file-directory))) | ||
| 3450 | (apply 'start-process | ||
| 3451 | (tramp-get-connection-property | ||
| 3452 | v "process-name" nil) | ||
| 3453 | (tramp-get-connection-property | ||
| 3454 | v "process-buffer" nil) | ||
| 3455 | copy-program | ||
| 3456 | (append copy-args (list source target)))))) | ||
| 3457 | (tramp-message | ||
| 3458 | v 6 "%s" (mapconcat 'identity (process-command p) " ")) | ||
| 3459 | (tramp-set-process-query-on-exit-flag p nil) | ||
| 3460 | (tramp-process-actions p v tramp-actions-copy-out-of-band)))) | ||
| 3461 | 3445 | ||
| 3462 | ;; Reset the transfer process properties. | 3446 | (unwind-protect |
| 3463 | (tramp-set-connection-property v "process-name" nil) | 3447 | (with-temp-buffer |
| 3464 | (tramp-set-connection-property v "process-buffer" nil)) | 3448 | ;; The default directory must be remote. |
| 3449 | (let ((default-directory | ||
| 3450 | (file-name-directory (if t1 filename newname)))) | ||
| 3451 | ;; Set the transfer process properties. | ||
| 3452 | (tramp-set-connection-property | ||
| 3453 | v "process-name" (buffer-name (current-buffer))) | ||
| 3454 | (tramp-set-connection-property | ||
| 3455 | v "process-buffer" (current-buffer)) | ||
| 3456 | |||
| 3457 | ;; Use an asynchronous process. By this, password can | ||
| 3458 | ;; be handled. The default directory must be local, in | ||
| 3459 | ;; order to apply the correct `copy-program'. We don't | ||
| 3460 | ;; set a timeout, because the copying of large files can | ||
| 3461 | ;; last longer than 60 secs. | ||
| 3462 | (let ((p (let ((default-directory | ||
| 3463 | (tramp-compat-temporary-file-directory))) | ||
| 3464 | (apply 'start-process | ||
| 3465 | (tramp-get-connection-property | ||
| 3466 | v "process-name" nil) | ||
| 3467 | (tramp-get-connection-property | ||
| 3468 | v "process-buffer" nil) | ||
| 3469 | copy-program | ||
| 3470 | (append copy-args (list source target)))))) | ||
| 3471 | (tramp-message | ||
| 3472 | v 6 "%s" (mapconcat 'identity (process-command p) " ")) | ||
| 3473 | (tramp-set-process-query-on-exit-flag p nil) | ||
| 3474 | (tramp-process-actions p v tramp-actions-copy-out-of-band)))) | ||
| 3465 | 3475 | ||
| 3466 | (tramp-message v 0 "Transferring %s to %s...done" filename newname) | 3476 | ;; Reset the transfer process properties. |
| 3477 | (tramp-set-connection-property v "process-name" nil) | ||
| 3478 | (tramp-set-connection-property v "process-buffer" nil)) | ||
| 3467 | 3479 | ||
| 3468 | ;; Handle KEEP-DATE argument. | 3480 | ;; Handle KEEP-DATE argument. |
| 3469 | (when (and keep-date (not copy-keep-date)) | 3481 | (when (and keep-date (not copy-keep-date)) |
| 3470 | (set-file-times newname (nth 5 (file-attributes filename)))) | 3482 | (set-file-times newname (nth 5 (file-attributes filename)))) |
| 3471 | 3483 | ||
| 3472 | ;; Set the mode. | 3484 | ;; Set the mode. |
| 3473 | (unless (and keep-date copy-keep-date) | 3485 | (unless (and keep-date copy-keep-date) |
| 3474 | (set-file-modes newname (tramp-default-file-modes filename)))) | 3486 | (set-file-modes newname (tramp-default-file-modes filename)))) |
| 3475 | 3487 | ||
| 3476 | ;; If the operation was `rename', delete the original file. | 3488 | ;; If the operation was `rename', delete the original file. |
| 3477 | (unless (eq op 'copy) | 3489 | (unless (eq op 'copy) |
| 3478 | (delete-file filename)))) | 3490 | (delete-file filename))))) |
| 3479 | 3491 | ||
| 3480 | (defun tramp-handle-make-directory (dir &optional parents) | 3492 | (defun tramp-handle-make-directory (dir &optional parents) |
| 3481 | "Like `make-directory' for Tramp files." | 3493 | "Like `make-directory' for Tramp files." |
| @@ -7855,6 +7867,7 @@ Only works for Bourne-like shells." | |||
| 7855 | ;; tramp-server-local-variable-alist) to define any such variables | 7867 | ;; tramp-server-local-variable-alist) to define any such variables |
| 7856 | ;; that they need to, which would then be let bound as appropriate | 7868 | ;; that they need to, which would then be let bound as appropriate |
| 7857 | ;; in tramp functions. (Jason Rumney) | 7869 | ;; in tramp functions. (Jason Rumney) |
| 7870 | ;; * Optimize out-of-band copying, when both methods are scp-like. | ||
| 7858 | 7871 | ||
| 7859 | ;; Functions for file-name-handler-alist: | 7872 | ;; Functions for file-name-handler-alist: |
| 7860 | ;; diff-latest-backup-file -- in diff.el | 7873 | ;; diff-latest-backup-file -- in diff.el |