]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tar-mode.el (tar-extract): Call tar--try-jka-compr (bug#34251)
authorJuri Linkov <juri@linkov.net>
Sun, 3 Feb 2019 21:00:29 +0000 (23:00 +0200)
committerJuri Linkov <juri@linkov.net>
Sun, 3 Feb 2019 21:00:29 +0000 (23:00 +0200)
* lisp/tar-mode.el (tar--try-jka-compr): New function copied from
archive-try-jka-compr.

* lisp/arc-mode.el (archive-try-jka-compr): Set buffer-multibyte to t
instead of let-binding coding-system-for-read to 'no-conversion.

* test/data/decompress/tg.tar.gz:
* test/data/decompress/zg.zip: New fixtures.

* test/lisp/arc-mode-tests.el (arc-mode-test-zip-extract-gz):
* test/lisp/tar-mode-tests.el (tar-mode-test-tar-extract-gz): New tests.

* test/lisp/vc/diff-mode-tests.el (diff-mode-test-font-lock)
(diff-mode-test-font-lock-syntax-one-line): Skip unless shell and
diff executables are found.

lisp/arc-mode.el
lisp/tar-mode.el
test/data/decompress/tg.tar.gz [new file with mode: 0644]
test/data/decompress/zg.zip [new file with mode: 0644]
test/lisp/arc-mode-tests.el
test/lisp/tar-mode-tests.el
test/lisp/vc/diff-mode-tests.el

index 263f251fc00994174bba9527228e56fb13602a98..2b5b6166ad55efb7995fcd86b9c4026031e11cc4 100644 (file)
@@ -967,9 +967,9 @@ using `make-temp-file', and the generated name is returned."
                   ;; Don't re-compress this data just before decompressing it.
                   (jka-compr-inhibit t))
               (write-region (point-min) (point-max) tmpfile nil 'quiet))
+            (set-buffer-multibyte t)
             (erase-buffer)
-            (let ((coding-system-for-read 'no-conversion))
-              (insert-file-contents tmpfile)))
+            (insert-file-contents tmpfile))
         (delete-file tmpfile)))))
 
 (defun archive-file-name-handler (op &rest args)
index 5b83d173b4aec87019269985b14c1a4309be44f5..c5382d3f3d1c64d6155d1cf3d7ab09da6b69074a 100644 (file)
@@ -852,6 +852,26 @@ actually appear on disk when you save the tar-file's buffer."
   (goto-char (posn-point (event-end event)))
   (tar-extract))
 
+(defun tar--try-jka-compr ()
+  (when (and auto-compression-mode
+             (jka-compr-get-compression-info buffer-file-name))
+    (let* ((basename (file-name-nondirectory buffer-file-name))
+           (tmpname (if (string-match ":\\([^:]+\\)\\'" basename)
+                        (match-string 1 basename) basename))
+           (tmpfile (make-temp-file (file-name-sans-extension tmpname)
+                                    nil
+                                    (file-name-extension tmpname 'period))))
+      (unwind-protect
+          (progn
+            (let ((coding-system-for-write 'no-conversion)
+                  ;; Don't re-compress this data just before decompressing it.
+                  (jka-compr-inhibit t))
+              (write-region (point-min) (point-max) tmpfile nil 'quiet))
+            (set-buffer-multibyte t)
+            (erase-buffer)
+            (insert-file-contents tmpfile))
+        (delete-file tmpfile)))))
+
 (defun tar-file-name-handler (op &rest args)
   "Helper function for `tar-extract'."
   (or (eq op 'file-exists-p)
@@ -931,6 +951,7 @@ actually appear on disk when you save the tar-file's buffer."
         (setq buffer-file-name new-buffer-file-name)
         (setq buffer-file-truename
               (abbreviate-file-name buffer-file-name))
+        (tar--try-jka-compr)       ;Pretty ugly hack :-(
         ;; Force buffer-file-coding-system to what
         ;; decode-coding-region actually used.
         (set-buffer-file-coding-system last-coding-system-used t)
diff --git a/test/data/decompress/tg.tar.gz b/test/data/decompress/tg.tar.gz
new file mode 100644 (file)
index 0000000..3dc8185
Binary files /dev/null and b/test/data/decompress/tg.tar.gz differ
diff --git a/test/data/decompress/zg.zip b/test/data/decompress/zg.zip
new file mode 100644 (file)
index 0000000..c4c998e
Binary files /dev/null and b/test/data/decompress/zg.zip differ
index e685767139399fb849981b2bcff2d6598165494f..79d3ac6365cf56c2314a94bbfc92923ac833d80f 100644 (file)
@@ -21,6 +21,8 @@
 (require 'ert)
 (require 'arc-mode)
 
+(defvar arc-mode-tests-data-directory
+  (expand-file-name "test/data/decompress" source-directory))
 
 (ert-deftest arc-mode-test-archive-int-to-mode ()
   (let ((alist (list (cons 448 "-rwx------")
     (dolist (x alist)
       (should (equal (cdr x) (archive-int-to-mode (car x)))))))
 
+(ert-deftest arc-mode-test-zip-extract-gz ()
+  (skip-unless (and archive-zip-extract (executable-find (car archive-zip-extract))))
+  (skip-unless (executable-find "gzip"))
+  (let* ((zip-file (expand-file-name "zg.zip" arc-mode-tests-data-directory))
+         zip-buffer gz-buffer)
+    (unwind-protect
+        (with-current-buffer (setq zip-buffer (find-file-noselect zip-file))
+          (setq gz-buffer (archive-extract))
+          (should (equal (char-after) ?\N{SNOWFLAKE})))
+      (when (buffer-live-p zip-buffer) (kill-buffer zip-buffer))
+      (when (buffer-live-p gz-buffer) (kill-buffer gz-buffer)))))
+
 (provide 'arc-mode-tests)
 
 ;; arc-mode-tests.el ends here
index 3ad0ced01d6afd77953f68d98949259ae650826b..1fce200721b5edf43284177040869c380b30634a 100644 (file)
@@ -21,6 +21,8 @@
 (require 'ert)
 (require 'tar-mode)
 
+(defvar tar-mode-tests-data-directory
+  (expand-file-name "test/data/decompress" source-directory))
 
 (ert-deftest tar-mode-test-tar-grind-file-mode ()
   (let ((alist (list (cons 448 "rwx------")
     (dolist (x alist)
       (should (equal (cdr x) (tar-grind-file-mode (car x)))))))
 
+(ert-deftest tar-mode-test-tar-extract-gz ()
+  (skip-unless (executable-find "gzip"))
+  (let* ((tar-file (expand-file-name "tg.tar.gz" tar-mode-tests-data-directory))
+         tar-buffer gz-buffer)
+    (unwind-protect
+        (with-current-buffer (setq tar-buffer (find-file-noselect tar-file))
+          (setq gz-buffer (tar-extract))
+          (should (equal (char-after) ?\N{SNOWFLAKE})))
+      (when (buffer-live-p tar-buffer) (kill-buffer tar-buffer))
+      (when (buffer-live-p gz-buffer) (kill-buffer gz-buffer)))))
+
 (provide 'tar-mode-tests)
 
 ;; tar-mode-tests.el ends here
index 8e690548f05fe967850f4a67b5dfcb622393e8cb..8695d958bac967ccc79c9e3e34e937e6eccb5ae9 100644 (file)
@@ -204,6 +204,8 @@ youthfulness
 
 (ert-deftest diff-mode-test-font-lock ()
   "Check font-locking of diff hunks."
+  (skip-unless (executable-find shell-file-name))
+  (skip-unless (executable-find diff-command))
   (let ((default-directory diff-mode-tests--datadir)
         (old "hello_world.c")
         (new "hello_emacs.c")
@@ -263,6 +265,8 @@ youthfulness
 
 (ert-deftest diff-mode-test-font-lock-syntax-one-line ()
   "Check diff syntax highlighting for one line with no newline at end."
+  (skip-unless (executable-find shell-file-name))
+  (skip-unless (executable-find diff-command))
   (let ((default-directory diff-mode-tests--datadir)
         (old "hello_world_1.c")
         (new "hello_emacs_1.c")