Subject: bug#10347: 24.0.50; archive-mode includes warning messages from unzip in the content of extracted files

From: Juri Linkov <[email-masked]>
Date: Sun, 25 Dec 2011 23:27:05 +0200

> Yes, this is a good idea. However, let's avoid duplicating the code by
> defining a function. Here's what I've got so far, although it doesn't
> actually display the messages, for whatever reason.

We can't remove special treatment of the 7z archiver because it produces
large output even on successful runs, so displaying it would be annoying.

I'd rather move the logic of displaying errors to `archive-extract-by-stdout'
where `stderr-test' defines the condition when not to display the output
redirected to stderr (in case of 7z it searches for the known regexp,
otherwise checks the buffer's size).

1. Tested it with "unzip": (setq archive-zip-extract '("unzip" "-qq" "-c"))

1.1. Visiting `omni.jar' displays in the echo area:

  warning [omni.jar]:  6552040 extra bytes at beginning or within zipfile
    (attempting to process anyway)
  error [omni.jar]:  reported length of central directory is
    -6552040 bytes too long (Atari STZip zipfile?  J.H.Holm ZIPSPLIT 1.1
    zipfile?).  Compensating...

1.2. Visiting the hand-edited `browser.jar' displays in the echo area:

  content/browser/aboutDialog.xul  bad CRC 1ded366d  (should be b80ec225)

2. Tested with using "7z": (setq archive-zip-extract '("7z" "x" "-so"))

2.1. Visiting `omni.jar' displays in the echo area:

  Processing archive: omni.jar
  Error: Can not open file as archive

2.2. Visiting the hand-edited `browser.jar' displays in the echo area:

  Processing archive: browser.jar
  Extracting  content/browser/aboutDialog.xul     CRC Failed
  Sub items Errors: 1

This all errors are reported to the user and easyly noticeable.

=== modified file 'lisp/arc-mode.el'
--- lisp/arc-mode.el	2011-12-15 07:24:10 +0000
+++ lisp/arc-mode.el	2011-12-25 21:27:01 +0000
@@ -1113,13 +1114,24 @@ (defun archive-*-extract (archive name c
     (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)
+	    (when (if (stringp stderr-test)
+		      (not (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-other-window ()
   "In archive mode, find this member in another window."
@@ -2095,17 +2125,11 @@ (defun archive-7z-summarize ()
       (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