Mercurial > emacs
comparison lisp/net/tramp.el @ 107170:1f564d6c5e1d
* net/tramp.el (tramp-do-copy-or-rename-file-out-of-band): Fix
errors in copying directories.
(tramp-handle-add-name-to-file, tramp-handle-copy-directory)
(tramp-do-copy-or-rename-file, tramp-handle-delete-directory)
(tramp-handle-delete-file)
(tramp-handle-dired-recursive-delete-directory)
(tramp-handle-write-region): Flush also the cache for the upper
directory.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Tue, 16 Feb 2010 17:03:29 +0100 |
parents | 7e66e7efd47d |
children | a48b193e3b5f |
comparison
equal
deleted
inserted
replaced
107169:566a19f1adb0 | 107170:1f564d6c5e1d |
---|---|
3418 "File %s already exists; make it a new name anyway? " | 3418 "File %s already exists; make it a new name anyway? " |
3419 newname))) | 3419 newname))) |
3420 (tramp-error | 3420 (tramp-error |
3421 v2 'file-error | 3421 v2 'file-error |
3422 "add-name-to-file: file %s already exists" newname)) | 3422 "add-name-to-file: file %s already exists" newname)) |
3423 (tramp-flush-file-property v2 (file-name-directory v2-localname)) | |
3423 (tramp-flush-file-property v2 v2-localname) | 3424 (tramp-flush-file-property v2 v2-localname) |
3424 (tramp-barf-unless-okay | 3425 (tramp-barf-unless-okay |
3425 v1 | 3426 v1 |
3426 (format "%s %s %s" ln (tramp-shell-quote-argument v1-localname) | 3427 (format "%s %s %s" ln (tramp-shell-quote-argument v1-localname) |
3427 (tramp-shell-quote-argument v2-localname)) | 3428 (tramp-shell-quote-argument v2-localname)) |
3476 (make-directory (file-name-directory newname) parents)) | 3477 (make-directory (file-name-directory newname) parents)) |
3477 (tramp-do-copy-or-rename-file-out-of-band | 3478 (tramp-do-copy-or-rename-file-out-of-band |
3478 'copy dirname newname keep-date)) | 3479 'copy dirname newname keep-date)) |
3479 ;; We must do it file-wise. | 3480 ;; We must do it file-wise. |
3480 (tramp-run-real-handler | 3481 (tramp-run-real-handler |
3481 'copy-directory (list dirname newname keep-date parents)))))) | 3482 'copy-directory (list dirname newname keep-date parents))) |
3483 | |
3484 ;; When newname did exist, we have wrong cached values. | |
3485 (when t2 | |
3486 (with-parsed-tramp-file-name newname nil | |
3487 (tramp-flush-file-property v (file-name-directory localname)) | |
3488 (tramp-flush-file-property v localname)))))) | |
3482 | 3489 |
3483 (defun tramp-handle-rename-file | 3490 (defun tramp-handle-rename-file |
3484 (filename newname &optional ok-if-already-exists) | 3491 (filename newname &optional ok-if-already-exists) |
3485 "Like `rename-file' for Tramp files." | 3492 "Like `rename-file' for Tramp files." |
3486 ;; Check if both files are local -- invoke normal rename-file. | 3493 ;; Check if both files are local -- invoke normal rename-file. |
3581 (error "Tramp implementation says this cannot happen"))) | 3588 (error "Tramp implementation says this cannot happen"))) |
3582 | 3589 |
3583 ;; In case of `rename', we must flush the cache of the source file. | 3590 ;; In case of `rename', we must flush the cache of the source file. |
3584 (when (and t1 (eq op 'rename)) | 3591 (when (and t1 (eq op 'rename)) |
3585 (with-parsed-tramp-file-name filename nil | 3592 (with-parsed-tramp-file-name filename nil |
3593 (tramp-flush-file-property v (file-name-directory localname)) | |
3586 (tramp-flush-file-property v localname))) | 3594 (tramp-flush-file-property v localname))) |
3587 | 3595 |
3588 ;; When newname did exist, we have wrong cached values. | 3596 ;; When newname did exist, we have wrong cached values. |
3589 (when t2 | 3597 (when t2 |
3590 (with-parsed-tramp-file-name newname nil | 3598 (with-parsed-tramp-file-name newname nil |
3599 (tramp-flush-file-property v (file-name-directory localname)) | |
3591 (tramp-flush-file-property v localname))) | 3600 (tramp-flush-file-property v localname))) |
3592 | 3601 |
3593 (with-parsed-tramp-file-name (if t1 filename newname) nil | 3602 (with-parsed-tramp-file-name (if t1 filename newname) nil |
3594 (tramp-message v 0 "Transferring %s to %s...done" filename newname))))) | 3603 (tramp-message v 0 "Transferring %s to %s...done" filename newname))))) |
3595 | 3604 |
3787 (with-parsed-tramp-file-name (if t1 filename newname) nil | 3796 (with-parsed-tramp-file-name (if t1 filename newname) nil |
3788 (if (and t1 t2) | 3797 (if (and t1 t2) |
3789 | 3798 |
3790 ;; Both are Tramp files. We shall optimize it, when the | 3799 ;; Both are Tramp files. We shall optimize it, when the |
3791 ;; methods for filename and newname are the same. | 3800 ;; methods for filename and newname are the same. |
3792 (let ((tmpfile (tramp-compat-make-temp-file localname))) | 3801 (let ((tmpfile |
3802 (if (file-regular-p filename) | |
3803 (tramp-compat-make-temp-file localname) | |
3804 (make-temp-name | |
3805 (expand-file-name | |
3806 tramp-temp-name-prefix | |
3807 (tramp-compat-temporary-file-directory)))))) | |
3793 (unwind-protect | 3808 (unwind-protect |
3794 (progn | 3809 (progn |
3795 (tramp-do-copy-or-rename-file-out-of-band | 3810 (tramp-do-copy-or-rename-file-out-of-band |
3796 op filename tmpfile keep-date) | 3811 op filename tmpfile keep-date) |
3797 (tramp-do-copy-or-rename-file-out-of-band | 3812 (tramp-do-copy-or-rename-file-out-of-band |
3798 'rename tmpfile newname keep-date)) | 3813 'rename tmpfile newname keep-date)) |
3799 ;; Save exit. | 3814 ;; Save exit. |
3800 (condition-case nil | 3815 (condition-case nil |
3801 (delete-file tmpfile) | 3816 (if (file-regular-p tmpfile) |
3817 (delete-file tmpfile) | |
3818 (delete-directory tmpfile 'recursive)) | |
3802 (error)))) | 3819 (error)))) |
3803 | 3820 |
3804 ;; Expand hops. Might be necessary for gateway methods. | 3821 ;; Expand hops. Might be necessary for gateway methods. |
3805 (setq v (car (tramp-compute-multi-hops v))) | 3822 (setq v (car (tramp-compute-multi-hops v))) |
3806 (aset v 3 localname) | 3823 (aset v 3 localname) |
3911 (unless (and keep-date copy-keep-date) | 3928 (unless (and keep-date copy-keep-date) |
3912 (set-file-modes newname (tramp-default-file-modes filename)))) | 3929 (set-file-modes newname (tramp-default-file-modes filename)))) |
3913 | 3930 |
3914 ;; If the operation was `rename', delete the original file. | 3931 ;; If the operation was `rename', delete the original file. |
3915 (unless (eq op 'copy) | 3932 (unless (eq op 'copy) |
3916 (delete-file filename))))) | 3933 (if (file-regular-p filename) |
3934 (delete-file filename) | |
3935 (delete-directory filename 'recursive)))))) | |
3917 | 3936 |
3918 (defun tramp-handle-make-directory (dir &optional parents) | 3937 (defun tramp-handle-make-directory (dir &optional parents) |
3919 "Like `make-directory' for Tramp files." | 3938 "Like `make-directory' for Tramp files." |
3920 (setq dir (expand-file-name dir)) | 3939 (setq dir (expand-file-name dir)) |
3921 (with-parsed-tramp-file-name dir nil | 3940 (with-parsed-tramp-file-name dir nil |
3930 | 3949 |
3931 (defun tramp-handle-delete-directory (directory &optional recursive) | 3950 (defun tramp-handle-delete-directory (directory &optional recursive) |
3932 "Like `delete-directory' for Tramp files." | 3951 "Like `delete-directory' for Tramp files." |
3933 (setq directory (expand-file-name directory)) | 3952 (setq directory (expand-file-name directory)) |
3934 (with-parsed-tramp-file-name directory nil | 3953 (with-parsed-tramp-file-name directory nil |
3954 (tramp-flush-file-property v (file-name-directory localname)) | |
3935 (tramp-flush-directory-property v localname) | 3955 (tramp-flush-directory-property v localname) |
3936 (unless (zerop (tramp-send-command-and-check | 3956 (unless (zerop (tramp-send-command-and-check |
3937 v | 3957 v |
3938 (format | 3958 (format |
3939 "%s %s" | 3959 "%s %s" |
3943 | 3963 |
3944 (defun tramp-handle-delete-file (filename) | 3964 (defun tramp-handle-delete-file (filename) |
3945 "Like `delete-file' for Tramp files." | 3965 "Like `delete-file' for Tramp files." |
3946 (setq filename (expand-file-name filename)) | 3966 (setq filename (expand-file-name filename)) |
3947 (with-parsed-tramp-file-name filename nil | 3967 (with-parsed-tramp-file-name filename nil |
3968 (tramp-flush-file-property v (file-name-directory localname)) | |
3948 (tramp-flush-file-property v localname) | 3969 (tramp-flush-file-property v localname) |
3949 (unless (zerop (tramp-send-command-and-check | 3970 (unless (zerop (tramp-send-command-and-check |
3950 v | 3971 v |
3951 (format "rm -f %s" | 3972 (format "rm -f %s" |
3952 (tramp-shell-quote-argument localname)))) | 3973 (tramp-shell-quote-argument localname)))) |
3972 nil t) | 3993 nil t) |
3973 ;; Wait for the remote system to return to us... | 3994 ;; Wait for the remote system to return to us... |
3974 ;; This might take a while, allow it plenty of time. | 3995 ;; This might take a while, allow it plenty of time. |
3975 (tramp-wait-for-output (tramp-get-connection-process v) 120) | 3996 (tramp-wait-for-output (tramp-get-connection-process v) 120) |
3976 ;; Make sure that it worked... | 3997 ;; Make sure that it worked... |
3998 (tramp-flush-file-property v (file-name-directory localname)) | |
3977 (tramp-flush-directory-property v localname) | 3999 (tramp-flush-directory-property v localname) |
3978 (and (file-exists-p filename) | 4000 (and (file-exists-p filename) |
3979 (tramp-error | 4001 (tramp-error |
3980 v 'file-error "Failed to recursively delete %s" filename)))) | 4002 v 'file-error "Failed to recursively delete %s" filename)))) |
3981 | 4003 |
4951 (and | 4973 (and |
4952 (file-writable-p (file-name-directory localname)) | 4974 (file-writable-p (file-name-directory localname)) |
4953 (or (file-directory-p localname) | 4975 (or (file-directory-p localname) |
4954 (file-writable-p localname))))) | 4976 (file-writable-p localname))))) |
4955 ;; Short track: if we are on the local host, we can run directly. | 4977 ;; Short track: if we are on the local host, we can run directly. |
4956 (progn | 4978 (tramp-run-real-handler |
4957 (tramp-run-real-handler | 4979 'write-region |
4958 'write-region | 4980 (list start end localname append 'no-message lockname confirm)) |
4959 (list start end localname append 'no-message lockname confirm)) | |
4960 (tramp-flush-file-property v localname)) | |
4961 | 4981 |
4962 (let ((rem-dec (tramp-get-remote-coding v "remote-decoding")) | 4982 (let ((rem-dec (tramp-get-remote-coding v "remote-decoding")) |
4963 (loc-enc (tramp-get-local-coding v "local-encoding")) | 4983 (loc-enc (tramp-get-local-coding v "local-encoding")) |
4964 (modes (save-excursion (tramp-default-file-modes filename))) | 4984 (modes (save-excursion (tramp-default-file-modes filename))) |
4965 ;; We use this to save the value of | 4985 ;; We use this to save the value of |
5119 v 'file-error | 5139 v 'file-error |
5120 (concat "Couldn't write region to `%s'," | 5140 (concat "Couldn't write region to `%s'," |
5121 " decode using `%s' failed") | 5141 " decode using `%s' failed") |
5122 filename rem-dec))) | 5142 filename rem-dec))) |
5123 (tramp-message | 5143 (tramp-message |
5124 v 5 "Decoding region into remote file %s...done" filename) | 5144 v 5 "Decoding region into remote file %s...done" filename)) |
5125 (tramp-flush-file-property v localname)) | |
5126 | 5145 |
5127 ;; Save exit. | 5146 ;; Save exit. |
5128 (delete-file tmpfile))) | 5147 (delete-file tmpfile))) |
5129 | 5148 |
5130 ;; That's not expected. | 5149 ;; That's not expected. |
5136 method))) | 5155 method))) |
5137 | 5156 |
5138 ;; Make `last-coding-system-used' have the right value. | 5157 ;; Make `last-coding-system-used' have the right value. |
5139 (when coding-system-used | 5158 (when coding-system-used |
5140 (set 'last-coding-system-used coding-system-used)))) | 5159 (set 'last-coding-system-used coding-system-used)))) |
5160 | |
5161 (tramp-flush-file-property v (file-name-directory localname)) | |
5162 (tramp-flush-file-property v localname) | |
5141 | 5163 |
5142 ;; We must protect `last-coding-system-used', now we have set it | 5164 ;; We must protect `last-coding-system-used', now we have set it |
5143 ;; to its correct value. | 5165 ;; to its correct value. |
5144 (let (last-coding-system-used (need-chown t)) | 5166 (let (last-coding-system-used (need-chown t)) |
5145 ;; Set file modification time. | 5167 ;; Set file modification time. |