emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110240: Display archive errors in th


From: Juri Linkov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110240: Display archive errors in the echo area instead of inserting to the file buffer.
Date: Fri, 28 Sep 2012 19:38:07 +0300
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110240
fixes bug: http://debbugs.gnu.org/10347
committer: Juri Linkov <address@hidden>
branch nick: trunk
timestamp: Fri 2012-09-28 19:38:07 +0300
message:
  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'.
modified:
  lisp/ChangeLog
  lisp/arc-mode.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-28 16:02:31 +0000
+++ b/lisp/ChangeLog    2012-09-28 16:38:07 +0000
@@ -1,3 +1,20 @@
+2012-09-28  Juri Linkov  <address@hidden>
+
+       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  <address@hidden>
 
        * pcomplete.el (pcomplete-show-completions): Use

=== modified file 'lisp/arc-mode.el'
--- a/lisp/arc-mode.el  2012-05-04 06:13:18 +0000
+++ b/lisp/arc-mode.el  2012-09-28 16:38:07 +0000
@@ -1117,13 +1117,54 @@
     (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 @@
       ;; 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 @@
       (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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]