diff options
| author | Katsumi Yamaoka | 2013-08-09 08:05:56 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2013-08-09 08:05:56 +0000 |
| commit | a025f7d63e69a9950a32afe8a6b6bfc04f5417a6 (patch) | |
| tree | 13bf8c777ae047145a4e3a969593369464599da5 | |
| parent | b042915834070ece4c0707446ce8d6108790556e (diff) | |
| download | emacs-a025f7d63e69a9950a32afe8a6b6bfc04f5417a6.tar.gz emacs-a025f7d63e69a9950a32afe8a6b6bfc04f5417a6.zip | |
Gnus: delete temporary files when Gnus exits instead of using timers
lisp/gnus/mm-decode.el (mm-temp-files-to-be-deleted,
mm-temp-files-cache-file): New internal variables.
(mm-temp-files-delete): New function; add it to gnus-exit-gnus-hook.
(mm-display-external): Use it to delete temporary files instead of
using timers.
| -rw-r--r-- | lisp/gnus/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/gnus/mm-decode.el | 62 |
2 files changed, 55 insertions, 15 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 96187c48844..ab776bfbb54 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-08-09 Katsumi Yamaoka <yamaoka@jpl.org> | ||
| 2 | |||
| 3 | * mm-decode.el (mm-temp-files-to-be-deleted, mm-temp-files-cache-file): | ||
| 4 | New internal variables. | ||
| 5 | (mm-temp-files-delete): New function; add it to gnus-exit-gnus-hook. | ||
| 6 | (mm-display-external): Use it to delete temporary files instead of | ||
| 7 | using timers. | ||
| 8 | |||
| 1 | 2013-08-06 Jan Tatarik <jan.tatarik@gmail.com> | 9 | 2013-08-06 Jan Tatarik <jan.tatarik@gmail.com> |
| 2 | 10 | ||
| 3 | * gnus-icalendar.el (gnus-icalendar-event-from-ical): Replace pcase | 11 | * gnus-icalendar.el (gnus-icalendar-event-from-ical): Replace pcase |
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el index 98d854340ee..2bfd145f174 100644 --- a/lisp/gnus/mm-decode.el +++ b/lisp/gnus/mm-decode.el | |||
| @@ -47,6 +47,7 @@ | |||
| 47 | (defvar gnus-current-window-configuration) | 47 | (defvar gnus-current-window-configuration) |
| 48 | 48 | ||
| 49 | (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list) | 49 | (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list) |
| 50 | (add-hook 'gnus-exit-gnus-hook 'mm-temp-files-delete) | ||
| 50 | 51 | ||
| 51 | (defgroup mime-display () | 52 | (defgroup mime-display () |
| 52 | "Display of MIME in mail and news articles." | 53 | "Display of MIME in mail and news articles." |
| @@ -470,6 +471,11 @@ If not set, `default-directory' will be used." | |||
| 470 | (defvar mm-content-id-alist nil) | 471 | (defvar mm-content-id-alist nil) |
| 471 | (defvar mm-postponed-undisplay-list nil) | 472 | (defvar mm-postponed-undisplay-list nil) |
| 472 | (defvar mm-inhibit-auto-detect-attachment nil) | 473 | (defvar mm-inhibit-auto-detect-attachment nil) |
| 474 | (defvar mm-temp-files-to-be-deleted nil | ||
| 475 | "List of temporary files scheduled to be deleted.") | ||
| 476 | (defvar mm-temp-files-cache-file (concat ".mm-temp-files-" (user-login-name)) | ||
| 477 | "Name of a file that caches a list of temporary files to be deleted. | ||
| 478 | The file will be saved in the directory `mm-tmp-directory'.") | ||
| 473 | 479 | ||
| 474 | ;; According to RFC2046, in particular, in a digest, the default | 480 | ;; According to RFC2046, in particular, in a digest, the default |
| 475 | ;; Content-Type value for a body part is changed from "text/plain" to | 481 | ;; Content-Type value for a body part is changed from "text/plain" to |
| @@ -586,6 +592,45 @@ Postpone undisplaying of viewers for types in | |||
| 586 | (message "Destroying external MIME viewers") | 592 | (message "Destroying external MIME viewers") |
| 587 | (mm-destroy-parts mm-postponed-undisplay-list))) | 593 | (mm-destroy-parts mm-postponed-undisplay-list))) |
| 588 | 594 | ||
| 595 | (defun mm-temp-files-delete () | ||
| 596 | "Delete temporary files and those parent directories. | ||
| 597 | Note that the deletion may fail if a program is catching hold of a file | ||
| 598 | under Windows or Cygwin. In that case, it schedules the deletion of | ||
| 599 | files left at the next time." | ||
| 600 | (let* ((coding-system-for-read mm-universal-coding-system) | ||
| 601 | (coding-system-for-write mm-universal-coding-system) | ||
| 602 | (cache-file (expand-file-name mm-temp-files-cache-file | ||
| 603 | mm-tmp-directory)) | ||
| 604 | (cache (when (file-exists-p cache-file) | ||
| 605 | (mm-with-multibyte-buffer | ||
| 606 | (insert-file-contents cache-file) | ||
| 607 | (split-string (buffer-string) "\n" t)))) | ||
| 608 | fails) | ||
| 609 | (dolist (temp (append cache mm-temp-files-to-be-deleted)) | ||
| 610 | (unless (and (file-exists-p temp) | ||
| 611 | (if (file-directory-p temp) | ||
| 612 | ;; A parent directory left at the previous time. | ||
| 613 | (progn | ||
| 614 | (ignore-errors (delete-directory temp)) | ||
| 615 | (not (file-exists-p temp))) | ||
| 616 | ;; Delete a temporary file and its parent directory. | ||
| 617 | (ignore-errors (delete-file temp)) | ||
| 618 | (and (not (file-exists-p temp)) | ||
| 619 | (progn | ||
| 620 | (setq temp (file-name-directory temp)) | ||
| 621 | (ignore-errors (delete-directory temp)) | ||
| 622 | (not (file-exists-p temp)))))) | ||
| 623 | (push temp fails))) | ||
| 624 | (if fails | ||
| 625 | ;; Schedule the deletion of the files left at the next time. | ||
| 626 | (progn | ||
| 627 | (write-region (concat (mapconcat 'identity (nreverse fails) "\n") | ||
| 628 | "\n") | ||
| 629 | nil cache-file nil 'silent) | ||
| 630 | (set-file-modes cache-file #o600)) | ||
| 631 | (when (file-exists-p cache-file) | ||
| 632 | (ignore-errors (delete-file cache-file)))))) | ||
| 633 | |||
| 589 | (autoload 'message-fetch-field "message") | 634 | (autoload 'message-fetch-field "message") |
| 590 | 635 | ||
| 591 | (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from) | 636 | (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from) |
| @@ -975,22 +1020,8 @@ external if displayed external." | |||
| 975 | (buffer buffer) | 1020 | (buffer buffer) |
| 976 | (command command) | 1021 | (command command) |
| 977 | (handle handle)) | 1022 | (handle handle)) |
| 978 | (run-at-time | ||
| 979 | 30.0 nil | ||
| 980 | (lambda () | ||
| 981 | (ignore-errors | ||
| 982 | (delete-file file)) | ||
| 983 | (ignore-errors | ||
| 984 | (delete-directory (file-name-directory file))))) | ||
| 985 | (lambda (process state) | 1023 | (lambda (process state) |
| 986 | (when (eq (process-status process) 'exit) | 1024 | (when (eq (process-status process) 'exit) |
| 987 | (run-at-time | ||
| 988 | 10.0 nil | ||
| 989 | (lambda () | ||
| 990 | (ignore-errors | ||
| 991 | (delete-file file)) | ||
| 992 | (ignore-errors | ||
| 993 | (delete-directory (file-name-directory file))))) | ||
| 994 | (when (buffer-live-p outbuf) | 1025 | (when (buffer-live-p outbuf) |
| 995 | (with-current-buffer outbuf | 1026 | (with-current-buffer outbuf |
| 996 | (let ((buffer-read-only nil) | 1027 | (let ((buffer-read-only nil) |
| @@ -1007,7 +1038,8 @@ external if displayed external." | |||
| 1007 | (kill-buffer buffer))) | 1038 | (kill-buffer buffer))) |
| 1008 | (message "Displaying %s...done" command))))) | 1039 | (message "Displaying %s...done" command))))) |
| 1009 | (mm-handle-set-external-undisplayer | 1040 | (mm-handle-set-external-undisplayer |
| 1010 | handle (cons file buffer))) | 1041 | handle (cons file buffer)) |
| 1042 | (add-to-list 'mm-temp-files-to-be-deleted file t)) | ||
| 1011 | (message "Displaying %s..." command)) | 1043 | (message "Displaying %s..." command)) |
| 1012 | 'external))))))) | 1044 | 'external))))))) |
| 1013 | 1045 | ||