comparison lisp/net/tramp.el @ 108806:511da81b16c5

Change delete-by-moving-to-trash so Lisp calls explicitly request trashing. * src/fileio.c (Fdelete_file): Change meaning of optional arg to mean whether to trash. (internal_delete_file, Frename_file): Callers changed. (delete_by_moving_to_trash): Doc fix. (Fdelete_directory_internal): Don't move to trash. * src/callproc.c (delete_temp_file): * src/buffer.c (Fkill_buffer): Callers changed. * src/lisp.h: Update prototype. * lisp/diff.el (diff-sentinel): * lisp/epg.el (epg--make-temp-file, epg-decrypt-string) (epg-verify-string, epg-sign-string, epg-encrypt-string): * lisp/jka-compr.el (jka-compr-partial-uncompress) (jka-compr-call-process, jka-compr-write-region): * lisp/server.el (server-sentinel): Remove optional arg from delete-file, reverting 2010-05-03 change. * lisp/dired.el (dired-delete-file): New arg TRASH. (dired-internal-do-deletions): New arg TRASH. Use progress reporter. (dired-do-flagged-delete, dired-do-delete): Use trash. * lisp/files.el (delete-directory): New arg TRASH. * lisp/speedbar.el (speedbar-item-delete): Allow trashing. * lisp/net/ange-ftp.el (ange-ftp-del-tmp-name, ange-ftp-delete-file) (ange-ftp-rename-remote-to-remote) (ange-ftp-rename-local-to-remote) (ange-ftp-rename-remote-to-local, ange-ftp-load) (ange-ftp-compress, ange-ftp-uncompress): Remove optional arg from `delete-file'. (ange-ftp-delete-directory): Add optional arg to `delete-file', to allow trashing. * lisp/net/tramp-compat.el (tramp-compat-delete-file): Rewrite to handle new TRASH arg of `delete-file'. * lisp/net/tramp-fish.el (tramp-fish-handle-delete-directory) (tramp-fish-handle-delete-file) (tramp-fish-handle-make-symbolic-link) (tramp-fish-handle-process-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Rename arg. (tramp-gvfs-handle-write-region): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-imap.el (tramp-imap-handle-delete-file): Rename arg. (tramp-imap-do-copy-or-rename-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-smb.el (tramp-smb-handle-copy-file) (tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file) (tramp-smb-handle-write-region): Use null TRASH arg in tramp-compat-delete-file call. (tramp-smb-handle-delete-directory): Use tramp-compat-delete-file. (tramp-smb-handle-delete-file): Rename arg. * lisp/net/tramp.el (tramp-handle-delete-file): Change FORCE arg to TRASH. (tramp-handle-make-symbolic-link, tramp-handle-load) (tramp-do-copy-or-rename-file-via-buffer) (tramp-do-copy-or-rename-file-directly) (tramp-do-copy-or-rename-file-out-of-band) (tramp-handle-process-file, tramp-handle-call-process-region) (tramp-handle-shell-command, tramp-handle-file-local-copy) (tramp-handle-insert-file-contents, tramp-handle-write-region) (tramp-delete-temp-file-function): Use null TRASH arg in tramp-compat-delete-file call.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 27 May 2010 19:30:11 -0400
parents 04bc013ba171
children 94d1d8a6dcfd
comparison
equal deleted inserted replaced
108805:78199a49c4bf 108806:511da81b16c5
2542 (format 2542 (format
2543 "File %s already exists; make it a link anyway? " 2543 "File %s already exists; make it a link anyway? "
2544 l-localname))))) 2544 l-localname)))))
2545 (tramp-error 2545 (tramp-error
2546 l 'file-already-exists "File %s already exists" l-localname) 2546 l 'file-already-exists "File %s already exists" l-localname)
2547 (tramp-compat-delete-file linkname 'force))) 2547 (tramp-compat-delete-file linkname)))
2548 2548
2549 ;; If FILENAME is a Tramp name, use just the localname component. 2549 ;; If FILENAME is a Tramp name, use just the localname component.
2550 (when (tramp-tramp-file-p filename) 2550 (when (tramp-tramp-file-p filename)
2551 (setq filename 2551 (setq filename
2552 (tramp-file-name-localname 2552 (tramp-file-name-localname
2591 (with-progress-reporter v 0 (format "Loading %s" file) 2591 (with-progress-reporter v 0 (format "Loading %s" file)
2592 (let ((local-copy (file-local-copy file))) 2592 (let ((local-copy (file-local-copy file)))
2593 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil. 2593 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
2594 (unwind-protect 2594 (unwind-protect
2595 (load local-copy noerror t t) 2595 (load local-copy noerror t t)
2596 (tramp-compat-delete-file local-copy 'force))))) 2596 (tramp-compat-delete-file local-copy)))))
2597 t))) 2597 t)))
2598 2598
2599 ;; Localname manipulation functions that grok Tramp localnames... 2599 ;; Localname manipulation functions that grok Tramp localnames...
2600 (defun tramp-handle-file-name-as-directory (file) 2600 (defun tramp-handle-file-name-as-directory (file)
2601 "Like `file-name-as-directory' but aware of Tramp files." 2601 "Like `file-name-as-directory' but aware of Tramp files."
3767 ;; KEEP-DATE handling. 3767 ;; KEEP-DATE handling.
3768 (when keep-date (set-file-times newname (nth 5 (file-attributes filename)))) 3768 (when keep-date (set-file-times newname (nth 5 (file-attributes filename))))
3769 ;; Set the mode. 3769 ;; Set the mode.
3770 (set-file-modes newname (tramp-default-file-modes filename)) 3770 (set-file-modes newname (tramp-default-file-modes filename))
3771 ;; If the operation was `rename', delete the original file. 3771 ;; If the operation was `rename', delete the original file.
3772 (unless (eq op 'copy) (tramp-compat-delete-file filename 'force))) 3772 (unless (eq op 'copy) (tramp-compat-delete-file filename)))
3773 3773
3774 (defun tramp-do-copy-or-rename-file-directly 3774 (defun tramp-do-copy-or-rename-file-directly
3775 (op filename newname ok-if-already-exists keep-date preserve-uid-gid) 3775 (op filename newname ok-if-already-exists keep-date preserve-uid-gid)
3776 "Invokes `cp' or `mv' on the remote system. 3776 "Invokes `cp' or `mv' on the remote system.
3777 OP must be one of `copy' or `rename', indicating `cp' or `mv', 3777 OP must be one of `copy' or `rename', indicating `cp' or `mv',
3922 'rename-file 3922 'rename-file
3923 (list tmpfile localname2 ok-if-already-exists))))) 3923 (list tmpfile localname2 ok-if-already-exists)))))
3924 3924
3925 ;; Save exit. 3925 ;; Save exit.
3926 (condition-case nil 3926 (condition-case nil
3927 (tramp-compat-delete-file tmpfile 'force) 3927 (tramp-compat-delete-file tmpfile)
3928 (error))))))))) 3928 (error)))))))))
3929 3929
3930 ;; Set the time and mode. Mask possible errors. 3930 ;; Set the time and mode. Mask possible errors.
3931 (condition-case nil 3931 (condition-case nil
3932 (when keep-date 3932 (when keep-date
3962 ;; Save exit. 3962 ;; Save exit.
3963 (condition-case nil 3963 (condition-case nil
3964 (if dir-flag 3964 (if dir-flag
3965 (tramp-compat-delete-directory 3965 (tramp-compat-delete-directory
3966 (expand-file-name ".." tmpfile) 'recursive) 3966 (expand-file-name ".." tmpfile) 'recursive)
3967 (tramp-compat-delete-file tmpfile 'force)) 3967 (tramp-compat-delete-file tmpfile))
3968 (error)))) 3968 (error))))
3969 3969
3970 ;; Expand hops. Might be necessary for gateway methods. 3970 ;; Expand hops. Might be necessary for gateway methods.
3971 (setq v (car (tramp-compute-multi-hops v))) 3971 (setq v (car (tramp-compute-multi-hops v)))
3972 (aset v 3 localname) 3972 (aset v 3 localname)
4080 (set-file-modes newname (tramp-default-file-modes filename))))) 4080 (set-file-modes newname (tramp-default-file-modes filename)))))
4081 4081
4082 ;; If the operation was `rename', delete the original file. 4082 ;; If the operation was `rename', delete the original file.
4083 (unless (eq op 'copy) 4083 (unless (eq op 'copy)
4084 (if (file-regular-p filename) 4084 (if (file-regular-p filename)
4085 (tramp-compat-delete-file filename 'force) 4085 (tramp-compat-delete-file filename)
4086 (tramp-compat-delete-directory filename 'recursive)))))) 4086 (tramp-compat-delete-directory filename 'recursive))))))
4087 4087
4088 (defun tramp-handle-make-directory (dir &optional parents) 4088 (defun tramp-handle-make-directory (dir &optional parents)
4089 "Like `make-directory' for Tramp files." 4089 "Like `make-directory' for Tramp files."
4090 (setq dir (expand-file-name dir)) 4090 (setq dir (expand-file-name dir))
4110 "%s %s" 4110 "%s %s"
4111 (if recursive "rm -rf" "rmdir") 4111 (if recursive "rm -rf" "rmdir")
4112 (tramp-shell-quote-argument localname)))) 4112 (tramp-shell-quote-argument localname))))
4113 (tramp-error v 'file-error "Couldn't delete %s" directory)))) 4113 (tramp-error v 'file-error "Couldn't delete %s" directory))))
4114 4114
4115 (defun tramp-handle-delete-file (filename &optional force) 4115 (defun tramp-handle-delete-file (filename &optional trash)
4116 "Like `delete-file' for Tramp files." 4116 "Like `delete-file' for Tramp files."
4117 (setq filename (expand-file-name filename)) 4117 (setq filename (expand-file-name filename))
4118 (with-parsed-tramp-file-name filename nil 4118 (with-parsed-tramp-file-name filename nil
4119 (tramp-flush-file-property v (file-name-directory localname)) 4119 (tramp-flush-file-property v (file-name-directory localname))
4120 (tramp-flush-file-property v localname) 4120 (tramp-flush-file-property v localname)
4627 ;; Provide error file. 4627 ;; Provide error file.
4628 (when tmpstderr (rename-file tmpstderr (cadr destination) t)) 4628 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
4629 4629
4630 ;; Cleanup. We remove all file cache values for the connection, 4630 ;; Cleanup. We remove all file cache values for the connection,
4631 ;; because the remote process could have changed them. 4631 ;; because the remote process could have changed them.
4632 (when tmpinput (tramp-compat-delete-file tmpinput 'force)) 4632 (when tmpinput (tramp-compat-delete-file tmpinput))
4633 4633
4634 ;; `process-file-side-effects' has been introduced with GNU 4634 ;; `process-file-side-effects' has been introduced with GNU
4635 ;; Emacs 23.2. If set to `nil', no remote file will be changed 4635 ;; Emacs 23.2. If set to `nil', no remote file will be changed
4636 ;; by `program'. If it doesn't exist, we assume its default 4636 ;; by `program'. If it doesn't exist, we assume its default
4637 ;; value 't'. 4637 ;; value 't'.
4664 (let ((tmpfile (tramp-compat-make-temp-file ""))) 4664 (let ((tmpfile (tramp-compat-make-temp-file "")))
4665 (write-region start end tmpfile) 4665 (write-region start end tmpfile)
4666 (when delete (delete-region start end)) 4666 (when delete (delete-region start end))
4667 (unwind-protect 4667 (unwind-protect
4668 (apply 'call-process program tmpfile buffer display args) 4668 (apply 'call-process program tmpfile buffer display args)
4669 (tramp-compat-delete-file tmpfile 'force)))) 4669 (tramp-compat-delete-file tmpfile))))
4670 4670
4671 (defun tramp-handle-shell-command 4671 (defun tramp-handle-shell-command
4672 (command &optional output-buffer error-buffer) 4672 (command &optional output-buffer error-buffer)
4673 "Like `shell-command' for Tramp files." 4673 "Like `shell-command' for Tramp files."
4674 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command)) 4674 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
4729 (apply 'process-file (car args) nil buffer nil (cdr args)) 4729 (apply 'process-file (car args) nil buffer nil (cdr args))
4730 ;; Insert error messages if they were separated. 4730 ;; Insert error messages if they were separated.
4731 (when (listp buffer) 4731 (when (listp buffer)
4732 (with-current-buffer error-buffer 4732 (with-current-buffer error-buffer
4733 (insert-file-contents (cadr buffer))) 4733 (insert-file-contents (cadr buffer)))
4734 (tramp-compat-delete-file (cadr buffer) 'force)) 4734 (tramp-compat-delete-file (cadr buffer)))
4735 (if current-buffer-p 4735 (if current-buffer-p
4736 ;; This is like exchange-point-and-mark, but doesn't 4736 ;; This is like exchange-point-and-mark, but doesn't
4737 ;; activate the mark. It is cleaner to avoid activation, 4737 ;; activate the mark. It is cleaner to avoid activation,
4738 ;; even though the command loop would deactivate the mark 4738 ;; even though the command loop would deactivate the mark
4739 ;; because we inserted text. 4739 ;; because we inserted text.
4811 v 3 (format "Decoding remote file %s with command %s" 4811 v 3 (format "Decoding remote file %s with command %s"
4812 filename loc-dec) 4812 filename loc-dec)
4813 (unwind-protect 4813 (unwind-protect
4814 (tramp-call-local-coding-command 4814 (tramp-call-local-coding-command
4815 loc-dec tmpfile2 tmpfile) 4815 loc-dec tmpfile2 tmpfile)
4816 (tramp-compat-delete-file tmpfile2 'force))))) 4816 (tramp-compat-delete-file tmpfile2)))))
4817 4817
4818 ;; Set proper permissions. 4818 ;; Set proper permissions.
4819 (set-file-modes tmpfile (tramp-default-file-modes filename)) 4819 (set-file-modes tmpfile (tramp-default-file-modes filename))
4820 ;; Set local user ownership. 4820 ;; Set local user ownership.
4821 (tramp-set-file-uid-gid tmpfile))) 4821 (tramp-set-file-uid-gid tmpfile)))
4824 (t (tramp-error 4824 (t (tramp-error
4825 v 'file-error "Wrong method specification for `%s'" method))) 4825 v 'file-error "Wrong method specification for `%s'" method)))
4826 4826
4827 ;; Error handling. 4827 ;; Error handling.
4828 ((error quit) 4828 ((error quit)
4829 (tramp-compat-delete-file tmpfile 'force) 4829 (tramp-compat-delete-file tmpfile)
4830 (signal (car err) (cdr err)))) 4830 (signal (car err) (cdr err))))
4831 4831
4832 (run-hooks 'tramp-handle-file-local-copy-hook) 4832 (run-hooks 'tramp-handle-file-local-copy-hook)
4833 tmpfile))) 4833 tmpfile)))
4834 4834
4959 (setq buffer-read-only (not (file-writable-p filename))) 4959 (setq buffer-read-only (not (file-writable-p filename)))
4960 (set-visited-file-modtime) 4960 (set-visited-file-modtime)
4961 (set-buffer-modified-p nil)) 4961 (set-buffer-modified-p nil))
4962 (when (and (stringp local-copy) 4962 (when (and (stringp local-copy)
4963 (or remote-copy (null tramp-temp-buffer-file-name))) 4963 (or remote-copy (null tramp-temp-buffer-file-name)))
4964 (tramp-compat-delete-file local-copy 'force)) 4964 (tramp-compat-delete-file local-copy))
4965 (when (stringp remote-copy) 4965 (when (stringp remote-copy)
4966 (tramp-compat-delete-file 4966 (tramp-compat-delete-file
4967 (tramp-make-tramp-file-name method user host remote-copy) 4967 (tramp-make-tramp-file-name method user host remote-copy))))))
4968 'force)))))
4969 4968
4970 ;; Result. 4969 ;; Result.
4971 (list (expand-file-name filename) 4970 (list (expand-file-name filename)
4972 (cadr result)))) 4971 (cadr result))))
4973 4972
5153 (tramp-run-real-handler 5152 (tramp-run-real-handler
5154 'write-region 5153 'write-region
5155 (list start end tmpfile append 'no-message lockname confirm)) 5154 (list start end tmpfile append 'no-message lockname confirm))
5156 ((error quit) 5155 ((error quit)
5157 (setq tramp-temp-buffer-file-name nil) 5156 (setq tramp-temp-buffer-file-name nil)
5158 (tramp-compat-delete-file tmpfile 'force) 5157 (tramp-compat-delete-file tmpfile)
5159 (signal (car err) (cdr err)))) 5158 (signal (car err) (cdr err))))
5160 5159
5161 ;; Now, `last-coding-system-used' has the right value. Remember it. 5160 ;; Now, `last-coding-system-used' has the right value. Remember it.
5162 (when (boundp 'last-coding-system-used) 5161 (when (boundp 'last-coding-system-used)
5163 (setq coding-system-used 5162 (setq coding-system-used
5197 ;; We keep the local file for performance 5196 ;; We keep the local file for performance
5198 ;; reasons, useful for "rsync". 5197 ;; reasons, useful for "rsync".
5199 (copy-file tmpfile filename t) 5198 (copy-file tmpfile filename t)
5200 ((error quit) 5199 ((error quit)
5201 (setq tramp-temp-buffer-file-name nil) 5200 (setq tramp-temp-buffer-file-name nil)
5202 (tramp-compat-delete-file tmpfile 'force) 5201 (tramp-compat-delete-file tmpfile)
5203 (signal (car err) (cdr err))))) 5202 (signal (car err) (cdr err)))))
5204 (setq tramp-temp-buffer-file-name nil) 5203 (setq tramp-temp-buffer-file-name nil)
5205 ;; Don't rename, in order to keep context in SELinux. 5204 ;; Don't rename, in order to keep context in SELinux.
5206 (unwind-protect 5205 (unwind-protect
5207 (copy-file tmpfile filename t) 5206 (copy-file tmpfile filename t)
5208 (tramp-compat-delete-file tmpfile 'force)))) 5207 (tramp-compat-delete-file tmpfile))))
5209 5208
5210 ;; Use inline file transfer. 5209 ;; Use inline file transfer.
5211 (rem-dec 5210 (rem-dec
5212 ;; Encode tmpfile. 5211 ;; Encode tmpfile.
5213 (unwind-protect 5212 (unwind-protect
5288 (concat "Couldn't write region to `%s'," 5287 (concat "Couldn't write region to `%s',"
5289 " decode using `%s' failed") 5288 " decode using `%s' failed")
5290 filename rem-dec))))) 5289 filename rem-dec)))))
5291 5290
5292 ;; Save exit. 5291 ;; Save exit.
5293 (tramp-compat-delete-file tmpfile 'force))) 5292 (tramp-compat-delete-file tmpfile)))
5294 5293
5295 ;; That's not expected. 5294 ;; That's not expected.
5296 (t 5295 (t
5297 (tramp-error 5296 (tramp-error
5298 v 'file-error 5297 v 'file-error
6371 6370
6372 (defun tramp-delete-temp-file-function () 6371 (defun tramp-delete-temp-file-function ()
6373 "Remove temporary files related to current buffer." 6372 "Remove temporary files related to current buffer."
6374 (when (stringp tramp-temp-buffer-file-name) 6373 (when (stringp tramp-temp-buffer-file-name)
6375 (condition-case nil 6374 (condition-case nil
6376 (tramp-compat-delete-file tramp-temp-buffer-file-name 'force) 6375 (tramp-compat-delete-file tramp-temp-buffer-file-name)
6377 (error nil)))) 6376 (error nil))))
6378 6377
6379 (add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function) 6378 (add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function)
6380 (add-hook 'tramp-cache-unload-hook 6379 (add-hook 'tramp-cache-unload-hook
6381 (lambda () 6380 (lambda ()