]> code.delx.au - gnu-emacs/commitdiff
Display archive errors in the echo area instead of inserting to the file buffer.
authorJuri Linkov <juri@jurta.org>
Fri, 28 Sep 2012 16:38:07 +0000 (19:38 +0300)
committerJuri Linkov <juri@jurta.org>
Fri, 28 Sep 2012 16:38:07 +0000 (19:38 +0300)
* 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
lisp/ChangeLog
lisp/arc-mode.el

index 4946fe5dd86630bc354c0932d80de26b71e571b1..b923b6aac58da7bc2b5bc89bacf0ef6aa6c4d478 100644 (file)
@@ -1,3 +1,20 @@
+2012-09-28  Juri Linkov  <juri@jurta.org>
+
+       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  <sdl.web@gmail.com>
 
        * pcomplete.el (pcomplete-show-completions): Use
index c776a3f8b5ce11a2149d7d6a6e53ad4d417db613..a97a052dc08fae676cee77b277c91673588a458e 100644 (file)
@@ -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