From 84716442f070dbf91fd3a1db173e130b78de561a Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Fri, 30 Apr 2010 22:19:40 -0400 Subject: [PATCH] Avoid using trash for certain temp files (Bug#6070). * server.el (server-sentinel, server-start, server-force-delete): * jka-compr.el (jka-compr-partial-uncompress) (jka-compr-call-process, jka-compr-write-region, jka-compr-load): * epg.el (epg--make-temp-file, epg-decrypt-string) (epg-encrypt-string, epg-verify-string, epg-sign-string): * diff.el (diff-sentinel): Bind delete-by-moving-to-trash to nil before deleting (Bug#6070). --- lisp/ChangeLog | 13 +++++++++++++ lisp/diff.el | 5 +++-- lisp/epg.el | 15 ++++++++++----- lisp/jka-compr.el | 16 +++++++++------- lisp/server.el | 10 +++++++--- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 101ce8ec1d9..7cac121af0c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,16 @@ +2010-05-01 Chong Yidong + + * server.el (server-sentinel, server-start, server-force-delete): + + * jka-compr.el (jka-compr-partial-uncompress) + (jka-compr-call-process, jka-compr-write-region, jka-compr-load): + + * epg.el (epg--make-temp-file, epg-decrypt-string) + (epg-encrypt-string, epg-verify-string, epg-sign-string): + + * diff.el (diff-sentinel): Bind delete-by-moving-to-trash to nil + before deleting (Bug#6070). + 2010-05-01 Stefan Monnier * bindings.el (mode-line-abbrev-mode, mode-line-auto-fill-mode): diff --git a/lisp/diff.el b/lisp/diff.el index 0206c17e770..37e52baaaac 100644 --- a/lisp/diff.el +++ b/lisp/diff.el @@ -64,8 +64,9 @@ "Code run when the diff process exits. CODE is the exit code of the process. It should be 0 only if no diffs were found." - (if diff-old-temp-file (delete-file diff-old-temp-file)) - (if diff-new-temp-file (delete-file diff-new-temp-file)) + (let (delete-by-moving-to-trash) + (if diff-old-temp-file (delete-file diff-old-temp-file)) + (if diff-new-temp-file (delete-file diff-new-temp-file))) (save-excursion (goto-char (point-max)) (let ((inhibit-read-only t)) diff --git a/lisp/epg.el b/lisp/epg.el index 9fde76d5f85..668043ebeb7 100644 --- a/lisp/epg.el +++ b/lisp/epg.el @@ -1898,7 +1898,8 @@ You can then use `write-region' to write new data into the file." ;; Cleanup the tempfile. (and tempfile (file-exists-p tempfile) - (delete-file tempfile)) + (let (delete-by-moving-to-trash) + (delete-file tempfile))) ;; Cleanup the tempdir. (and tempdir (file-directory-p tempdir) @@ -1998,7 +1999,8 @@ If PLAIN is nil, it returns the result as a string." (epg-read-output context)) (epg-delete-output-file context) (if (file-exists-p input-file) - (delete-file input-file)) + (let (delete-by-moving-to-trash) + (delete-file input-file))) (epg-reset context)))) (defun epg-start-verify (context signature &optional signed-text) @@ -2095,7 +2097,8 @@ successful verification." (epg-delete-output-file context) (if (and input-file (file-exists-p input-file)) - (delete-file input-file)) + (let (delete-by-moving-to-trash) + (delete-file input-file))) (epg-reset context)))) (defun epg-start-sign (context plain &optional mode) @@ -2202,7 +2205,8 @@ Otherwise, it makes a cleartext signature." (epg-read-output context)) (epg-delete-output-file context) (if input-file - (delete-file input-file)) + (let (delete-by-moving-to-trash) + (delete-file input-file))) (epg-reset context)))) (defun epg-start-encrypt (context plain recipients @@ -2322,7 +2326,8 @@ If RECIPIENTS is nil, it performs symmetric encryption." (epg-read-output context)) (epg-delete-output-file context) (if input-file - (delete-file input-file)) + (let (delete-by-moving-to-trash) + (delete-file input-file))) (epg-reset context)))) (defun epg-start-export-keys (context keys) diff --git a/lisp/jka-compr.el b/lisp/jka-compr.el index 34ffcc90a76..6df57d710e1 100644 --- a/lisp/jka-compr.el +++ b/lisp/jka-compr.el @@ -181,7 +181,9 @@ to keep: LEN chars starting BEG chars from the beginning." null-device)) jka-compr-acceptable-retval-list) (jka-compr-error prog args infile message err-file)) - (jka-compr-delete-temp-file err-file))) + (let (delete-by-moving-to-trash) + (delete-file err-file)))) + ;; Run the uncompression program directly. ;; We get the whole file and must delete what we don't want. (jka-compr-call-process prog message infile t nil args)) @@ -222,7 +224,8 @@ to keep: LEN chars starting BEG chars from the beginning." ""))) jka-compr-acceptable-retval-list) (jka-compr-error prog args infile message err-file)) - (jka-compr-delete-temp-file err-file))) + (let (delete-by-moving-to-trash) + (delete-file err-file)))) (or (eq 0 (apply 'call-process prog infile (if (stringp output) temp output) @@ -248,9 +251,6 @@ There should be no more than seven characters after the final `/'." "This routine will return the name of a new file." (make-temp-file jka-compr-temp-name-template)) -(defalias 'jka-compr-delete-temp-file 'delete-file) - - (defun jka-compr-write-region (start end file &optional append visit) (let* ((filename (expand-file-name file)) (visit-file (if (stringp visit) (expand-file-name visit) filename)) @@ -337,7 +337,8 @@ There should be no more than seven characters after the final `/'." (and append can-append) 'dont)) (erase-buffer)) ) - (jka-compr-delete-temp-file temp-file) + (let (delete-by-moving-to-trash) + (delete-file temp-file)) (and compress-message @@ -603,7 +604,8 @@ There should be no more than seven characters after the final `/'." (setq file (file-name-sans-extension file))) (setcar l file))) - (jka-compr-delete-temp-file local-copy)) + (let (delete-by-moving-to-trash) + (delete-file local-copy))) t)) diff --git a/lisp/server.el b/lisp/server.el index d36b99cc5b6..56819112639 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -344,7 +344,9 @@ If CLIENT is non-nil, add a description of it to the logged message." ;; for possible servers before doing anything, so it *should* be ours. (and (process-contact proc :server) (eq (process-status proc) 'closed) - (ignore-errors (delete-file (process-get proc :server-file)))) + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file (process-get proc :server-file))))) (server-log (format "Status changed to %s: %s" (process-status proc) msg) proc) (server-delete-client proc)) @@ -517,7 +519,9 @@ To force-start a server, do \\[server-force-delete] and then ;; Delete the socket files made by previous server invocations. (if (not (eq t (server-running-p server-name))) ;; Remove any leftover socket or authentication file - (ignore-errors (delete-file server-file)) + (ignore-errors + (let (delete-by-moving-to-trash) + (delete-file server-file))) (setq server-mode nil) ;; already set by the minor mode code (display-warning 'server @@ -600,7 +604,7 @@ NAME defaults to `server-name'. With argument, ask for NAME." server-auth-dir server-socket-dir)))) (condition-case nil - (progn + (let (delete-by-moving-to-trash) (delete-file file) (message "Connection file %S deleted" file)) (file-error -- 2.39.2