aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2012-09-28 19:38:07 +0300
committerJuri Linkov2012-09-28 19:38:07 +0300
commit53baf48a6e99b5ff434d5177b00beda3fc9a8f71 (patch)
tree8c9bd919742f9f986a342b7b1968ccfd1eee5737
parente61d39cddfd015032a6419ce75c36ecdf1e9fe9f (diff)
downloademacs-53baf48a6e99b5ff434d5177b00beda3fc9a8f71.tar.gz
emacs-53baf48a6e99b5ff434d5177b00beda3fc9a8f71.zip
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
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/arc-mode.el83
2 files changed, 71 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4946fe5dd86..b923b6aac58 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12012-09-28 Juri Linkov <juri@jurta.org>
2
3 Display archive errors in the echo area instead of inserting
4 to the file buffer.
5
6 * arc-mode.el (archive-extract-by-stdout): Change arg STDERR-FILE
7 to STDERR-TEST that can be a regexp matching a successful output.
8 Create a temporary file and redirect stderr to it. Search for
9 STDERR-TEST in the stderr output and display it in the echo area
10 if no match is found.
11 (archive-extract-by-file): New function like
12 `archive-extract-by-stdout' but extracting archives to files
13 and looking for successful matches in stdout. Function body is
14 mostly copied from `archive-rar-extract'.
15 (archive-rar-extract): Use `archive-extract-by-file'.
16 (archive-7z-extract): Use `archive-extract-by-stdout'. (Bug#10347)
17
12012-09-28 Leo Liu <sdl.web@gmail.com> 182012-09-28 Leo Liu <sdl.web@gmail.com>
2 19
3 * pcomplete.el (pcomplete-show-completions): Use 20 * 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."
1117 (archive-delete-local tmpfile) 1117 (archive-delete-local tmpfile)
1118 success)) 1118 success))
1119 1119
1120(defun archive-extract-by-stdout (archive name command &optional stderr-file) 1120(defun archive-extract-by-stdout (archive name command &optional stderr-test)
1121 (apply 'call-process 1121 (let ((stderr-file (make-temp-file "arc-stderr")))
1122 (car command) 1122 (unwind-protect
1123 nil 1123 (prog1
1124 (if stderr-file (list t stderr-file) t) 1124 (apply 'call-process
1125 nil 1125 (car command)
1126 (append (cdr command) (list archive name)))) 1126 nil
1127 (if stderr-file (list t stderr-file) t)
1128 nil
1129 (append (cdr command) (list archive name)))
1130 (with-temp-buffer
1131 (insert-file-contents stderr-file)
1132 (goto-char (point-min))
1133 (when (if (stringp stderr-test)
1134 (not (re-search-forward stderr-test nil t))
1135 (> (buffer-size) 0))
1136 (message "%s" (buffer-string)))))
1137 (if (file-exists-p stderr-file)
1138 (delete-file stderr-file)))))
1139
1140(defun archive-extract-by-file (archive name command &optional stdout-test)
1141 (let ((dest (make-temp-file "arc-dir" 'dir))
1142 (stdout-file (make-temp-file "arc-stdout")))
1143 (unwind-protect
1144 (prog1
1145 (apply 'call-process
1146 (car command)
1147 nil
1148 `(:file ,stdout-file)
1149 nil
1150 (append (cdr command) (list archive name dest)))
1151 (with-temp-buffer
1152 (insert-file-contents stdout-file)
1153 (goto-char (point-min))
1154 (when (if (stringp stdout-test)
1155 (not (re-search-forward stdout-test nil t))
1156 (> (buffer-size) 0))
1157 (message "%s" (buffer-string))))
1158 (if (file-exists-p (expand-file-name name dest))
1159 (insert-file-contents-literally (expand-file-name name dest))))
1160 (if (file-exists-p stdout-file)
1161 (delete-file stdout-file))
1162 (if (file-exists-p (expand-file-name name dest))
1163 (delete-file (expand-file-name name dest)))
1164 (while (file-name-directory name)
1165 (setq name (directory-file-name (file-name-directory name)))
1166 (delete-directory (expand-file-name name dest)))
1167 (delete-directory dest))))
1127 1168
1128(defun archive-extract-other-window () 1169(defun archive-extract-other-window ()
1129 "In archive mode, find this member in another window." 1170 "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."
2006 ;; The code below assumes the name is relative and may do undesirable 2047 ;; The code below assumes the name is relative and may do undesirable
2007 ;; things otherwise. 2048 ;; things otherwise.
2008 (error "Can't extract files with non-relative names") 2049 (error "Can't extract files with non-relative names")
2009 (let ((dest (make-temp-file "arc-rar" 'dir))) 2050 (archive-extract-by-file archive name '("unrar-free" "--extract") "All OK")))
2010 (unwind-protect
2011 (progn
2012 (call-process "unrar-free" nil nil nil
2013 "--extract" archive name dest)
2014 (insert-file-contents-literally (expand-file-name name dest)))
2015 (delete-file (expand-file-name name dest))
2016 (while (file-name-directory name)
2017 (setq name (directory-file-name (file-name-directory name)))
2018 (delete-directory (expand-file-name name dest)))
2019 (delete-directory dest)))))
2020 2051
2021;;; Section: Rar self-extracting .exe archives. 2052;;; Section: Rar self-extracting .exe archives.
2022 2053
@@ -2099,17 +2130,11 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
2099 (apply 'vector files)))) 2130 (apply 'vector files))))
2100 2131
2101(defun archive-7z-extract (archive name) 2132(defun archive-7z-extract (archive name)
2102 (let ((tmpfile (make-temp-file "7z-stderr"))) 2133 ;; 7z doesn't provide a `quiet' option to suppress non-essential
2103 ;; 7z doesn't provide a `quiet' option to suppress non-essential 2134 ;; stderr messages. So redirect stderr to a temp file and display it
2104 ;; stderr messages. So redirect stderr to a temp file and display it 2135 ;; in the echo area when it contains no message indicating success.
2105 ;; in the echo area when it contains error messages. 2136 (archive-extract-by-stdout
2106 (prog1 (archive-extract-by-stdout 2137 archive name archive-7z-extract "Everything is Ok"))
2107 archive name archive-7z-extract tmpfile)
2108 (with-temp-buffer
2109 (insert-file-contents tmpfile)
2110 (unless (search-forward "Everything is Ok" nil t)
2111 (message "%s" (buffer-string)))
2112 (delete-file tmpfile)))))
2113 2138
2114(defun archive-7z-write-file-member (archive descr) 2139(defun archive-7z-write-file-member (archive descr)
2115 (archive-*-write-file-member 2140 (archive-*-write-file-member