all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Daniel Brooks <db48x@db48x.net>
Cc: 10347@debbugs.gnu.org
Subject: bug#10347: 24.0.50; archive-mode includes warning messages from unzip in the content of extracted files
Date: Sun, 25 Dec 2011 23:28:52 +0200	[thread overview]
Message-ID: <877h1kwdd3.fsf@mail.jurta.org> (raw)
In-Reply-To: <m3mxaim7j6.fsf@db48x.net> (Daniel Brooks's message of "Thu, 22 Dec 2011 14:23:30 -0800")

Actually, `archive-rar-extract' has exactly the same problem.
When `unrar-free' can't extract some files from RAR archives,
it displays a confusing message:

  Removing old name: no such file or directory, /tmp/arc-rar1971TAO/file.txt

It needs the same treatment as 7z and zip.  But the difference is that
`unrar-free' outputs only to stdout, not to stderr.  And when the operation
is successful, it outputs long text with the known fixed message
"All OK" indicating success.  So we should check for this message,
and not display a message on success.

Here is a patch that adds `archive-extract-by-file' for RAR archives:

=== 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
@@ -1996,23 +2008,41 @@ (defun archive-rar-summarize (&optional
       (insert sep (make-string maxname ?-) "\n")
       (apply 'vector files))))
 
+(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)
+	    (when (if (stringp stdout-test)
+		      (not (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-rar-extract (archive name)
   ;; unrar-free seems to have no way to extract to stdout or even to a file.
   (if (file-name-absolute-p name)
       ;; 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.
 





  parent reply	other threads:[~2011-12-25 21:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-21 21:44 bug#10347: 24.0.50; archive-mode includes warning messages from unzip in the content of extracted files Daniel Brooks
2011-12-22 20:07 ` Juri Linkov
2011-12-22 22:23   ` Daniel Brooks
2011-12-25 21:27     ` Juri Linkov
2011-12-25 21:28     ` Juri Linkov [this message]
2012-09-28 16:38 ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877h1kwdd3.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=10347@debbugs.gnu.org \
    --cc=db48x@db48x.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.