From: Juri Linkov Date: Fri, 28 Sep 2012 16:38:07 +0000 (+0300) Subject: Display archive errors in the echo area instead of inserting to the file buffer. X-Git-Tag: emacs-24.2.90~244^2~43 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=53baf48a6e99b5ff434d5177b00beda3fc9a8f71;p=emacs.git Display archive errors in the echo area instead of inserting to the file buffer. * lisp/arc-mode.el (archive-extract-by-stdout): Change arg STDERR-FILE to STDERR-TEST that can be a regexp matching a successful output. Create a temporary file and redirect stderr to it. Search for STDERR-TEST in the stderr output and display it in the echo area if no match is found. (archive-extract-by-file): New function like `archive-extract-by-stdout' but extracting archives to files and looking for successful matches in stdout. Function body is mostly copied from `archive-rar-extract'. (archive-rar-extract): Use `archive-extract-by-file'. (archive-7z-extract): Use `archive-extract-by-stdout'. Fixes: debbugs:10347 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4946fe5dd86..b923b6aac58 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,20 @@ +2012-09-28 Juri Linkov + + Display archive errors in the echo area instead of inserting + to the file buffer. + + * arc-mode.el (archive-extract-by-stdout): Change arg STDERR-FILE + to STDERR-TEST that can be a regexp matching a successful output. + Create a temporary file and redirect stderr to it. Search for + STDERR-TEST in the stderr output and display it in the echo area + if no match is found. + (archive-extract-by-file): New function like + `archive-extract-by-stdout' but extracting archives to files + and looking for successful matches in stdout. Function body is + mostly copied from `archive-rar-extract'. + (archive-rar-extract): Use `archive-extract-by-file'. + (archive-7z-extract): Use `archive-extract-by-stdout'. (Bug#10347) + 2012-09-28 Leo Liu * pcomplete.el (pcomplete-show-completions): Use diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index c776a3f8b5c..a97a052dc08 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -1117,13 +1117,54 @@ using `make-temp-file', and the generated name is returned." (archive-delete-local tmpfile) success)) -(defun archive-extract-by-stdout (archive name command &optional stderr-file) - (apply 'call-process - (car command) - nil - (if stderr-file (list t stderr-file) t) - nil - (append (cdr command) (list archive name)))) +(defun archive-extract-by-stdout (archive name command &optional stderr-test) + (let ((stderr-file (make-temp-file "arc-stderr"))) + (unwind-protect + (prog1 + (apply 'call-process + (car command) + nil + (if stderr-file (list t stderr-file) t) + nil + (append (cdr command) (list archive name))) + (with-temp-buffer + (insert-file-contents stderr-file) + (goto-char (point-min)) + (when (if (stringp stderr-test) + (not (re-search-forward stderr-test nil t)) + (> (buffer-size) 0)) + (message "%s" (buffer-string))))) + (if (file-exists-p stderr-file) + (delete-file stderr-file))))) + +(defun archive-extract-by-file (archive name command &optional stdout-test) + (let ((dest (make-temp-file "arc-dir" 'dir)) + (stdout-file (make-temp-file "arc-stdout"))) + (unwind-protect + (prog1 + (apply 'call-process + (car command) + nil + `(:file ,stdout-file) + nil + (append (cdr command) (list archive name dest))) + (with-temp-buffer + (insert-file-contents stdout-file) + (goto-char (point-min)) + (when (if (stringp stdout-test) + (not (re-search-forward stdout-test nil t)) + (> (buffer-size) 0)) + (message "%s" (buffer-string)))) + (if (file-exists-p (expand-file-name name dest)) + (insert-file-contents-literally (expand-file-name name dest)))) + (if (file-exists-p stdout-file) + (delete-file stdout-file)) + (if (file-exists-p (expand-file-name name dest)) + (delete-file (expand-file-name name dest))) + (while (file-name-directory name) + (setq name (directory-file-name (file-name-directory name))) + (delete-directory (expand-file-name name dest))) + (delete-directory dest)))) (defun archive-extract-other-window () "In archive mode, find this member in another window." @@ -2006,17 +2047,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." ;; The code below assumes the name is relative and may do undesirable ;; things otherwise. (error "Can't extract files with non-relative names") - (let ((dest (make-temp-file "arc-rar" 'dir))) - (unwind-protect - (progn - (call-process "unrar-free" nil nil nil - "--extract" archive name dest) - (insert-file-contents-literally (expand-file-name name dest))) - (delete-file (expand-file-name name dest)) - (while (file-name-directory name) - (setq name (directory-file-name (file-name-directory name))) - (delete-directory (expand-file-name name dest))) - (delete-directory dest))))) + (archive-extract-by-file archive name '("unrar-free" "--extract") "All OK"))) ;;; Section: Rar self-extracting .exe archives. @@ -2099,17 +2130,11 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." (apply 'vector files)))) (defun archive-7z-extract (archive name) - (let ((tmpfile (make-temp-file "7z-stderr"))) - ;; 7z doesn't provide a `quiet' option to suppress non-essential - ;; stderr messages. So redirect stderr to a temp file and display it - ;; in the echo area when it contains error messages. - (prog1 (archive-extract-by-stdout - archive name archive-7z-extract tmpfile) - (with-temp-buffer - (insert-file-contents tmpfile) - (unless (search-forward "Everything is Ok" nil t) - (message "%s" (buffer-string))) - (delete-file tmpfile))))) + ;; 7z doesn't provide a `quiet' option to suppress non-essential + ;; stderr messages. So redirect stderr to a temp file and display it + ;; in the echo area when it contains no message indicating success. + (archive-extract-by-stdout + archive name archive-7z-extract "Everything is Ok")) (defun archive-7z-write-file-member (archive descr) (archive-*-write-file-member