Function: mm-temp-files-delete

mm-temp-files-delete is a byte-compiled function defined in mm-decode.el.gz.

Signature

(mm-temp-files-delete)

Documentation

Delete temporary files and those parent directories.

Note that the deletion may fail if a program is catching hold of a file under Windows or Cygwin. In that case, it schedules the deletion of files left at the next time.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/mm-decode.el.gz
(defun mm-temp-files-delete ()
  "Delete temporary files and those parent directories.
Note that the deletion may fail if a program is catching hold of a file
under Windows or Cygwin.  In that case, it schedules the deletion of
files left at the next time."
  (let* ((coding-system-for-read mm-universal-coding-system)
	 (coding-system-for-write mm-universal-coding-system)
	 (cache-file (expand-file-name mm-temp-files-cache-file
				       mm-tmp-directory))
	 (cache (when (file-exists-p cache-file)
		  (mm-with-multibyte-buffer
		    (insert-file-contents cache-file)
		    (split-string (buffer-string) "\n" t))))
	 fails)
    (dolist (temp (append cache mm-temp-files-to-be-deleted))
      (when (and (file-exists-p temp)
		 (if (file-directory-p temp)
		     ;; A parent directory left at the previous time.
		     (progn
		       (ignore-errors (delete-directory temp))
		       (file-exists-p temp))
		   ;; Delete a temporary file and its parent directory.
		   (ignore-errors (delete-file temp))
		   (or (file-exists-p temp)
		       (progn
			 (setq temp (file-name-directory temp))
			 (ignore-errors (delete-directory temp))
			 (file-exists-p temp)))))
	(push temp fails)))
    (if fails
	;; Schedule the deletion of the files left at the next time.
	(with-file-modes #o600
	  (write-region (concat (mapconcat #'identity (nreverse fails) "\n")
				"\n")
			nil cache-file nil 'silent))
      (when (file-exists-p cache-file)
	(ignore-errors (delete-file cache-file))))
    (setq mm-temp-files-to-be-deleted nil)))