diff options
| author | Ruijie Yu | 2023-03-06 11:03:32 +0800 |
|---|---|---|
| committer | Eli Zaretskii | 2023-04-20 12:26:05 +0300 |
| commit | fd4c9246fc8daea4965b868e80e0f2d9d544dc22 (patch) | |
| tree | 1ae2a962dad71de1ed46e283fa9b19b21aa5c722 /test | |
| parent | e0c8e4f12fb18695f309b1fd5ff26513ac5611e5 (diff) | |
| download | emacs-fd4c9246fc8daea4965b868e80e0f2d9d544dc22.tar.gz emacs-fd4c9246fc8daea4965b868e80e0f2d9d544dc22.zip | |
Handle modifications in extensionless zip files (bug#61326)
* lisp/arc-mode.el (archive-*-write-file-member)
(archive-*-expunge): Refactor to correctly modify
extensionless zip archives.
(archive-expunge): Move implementation to a separate helper
function to facilitate testing.
(archive--act-files): New helper function to wrap around
`call-process' calls.
(archive--need-rename-p): New helper function to check whether
a temporary rename is necessary.
(archive--ensure-extension) (archive--maybe-rename): New helper
functions to rename archive if the caller deems it necessary.
(archive--with-ensure-extension): New helper function to handle
writing an archive while ensuring extensionless archives work
correctly by temporarily renaming them.
* test/lisp/arc-mode-tests.el (arc-mode-test-zip-ensure-ext):
New regression test for bug#61326.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/arc-mode-tests.el | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/lisp/arc-mode-tests.el b/test/lisp/arc-mode-tests.el index 32bce1b71bd..b6e06a563fe 100644 --- a/test/lisp/arc-mode-tests.el +++ b/test/lisp/arc-mode-tests.el | |||
| @@ -46,6 +46,73 @@ | |||
| 46 | (when (buffer-live-p zip-buffer) (kill-buffer zip-buffer)) | 46 | (when (buffer-live-p zip-buffer) (kill-buffer zip-buffer)) |
| 47 | (when (buffer-live-p gz-buffer) (kill-buffer gz-buffer))))) | 47 | (when (buffer-live-p gz-buffer) (kill-buffer gz-buffer))))) |
| 48 | 48 | ||
| 49 | (ert-deftest arc-mode-test-zip-ensure-ext () | ||
| 50 | "Regression test for bug#61326." | ||
| 51 | (skip-unless (executable-find "zip")) | ||
| 52 | (let* ((default-directory arc-mode-tests-data-directory) | ||
| 53 | (base-zip-1 "base-1.zip") | ||
| 54 | (base-zip-2 "base-2.zip") | ||
| 55 | (content-1 '("1" "2")) | ||
| 56 | (content-2 '("3" "4")) | ||
| 57 | (make-file (lambda (name) | ||
| 58 | (with-temp-buffer | ||
| 59 | (insert name) | ||
| 60 | (write-file name)))) | ||
| 61 | (make-zip | ||
| 62 | (lambda (zip files) | ||
| 63 | (delete-file zip nil) | ||
| 64 | (funcall (archive--act-files '("zip") files) zip))) | ||
| 65 | (update-fn | ||
| 66 | (lambda (zip-nonempty) | ||
| 67 | (with-current-buffer (find-file-noselect zip-nonempty) | ||
| 68 | (save-excursion | ||
| 69 | (goto-char archive-file-list-start) | ||
| 70 | (save-current-buffer | ||
| 71 | (archive-extract) | ||
| 72 | (save-excursion | ||
| 73 | (goto-char (point-max)) | ||
| 74 | (insert ?a) | ||
| 75 | (save-buffer)) | ||
| 76 | (kill-buffer (current-buffer))) | ||
| 77 | (archive-extract) | ||
| 78 | ;; [2] must be ?a; [3] must be (eobp) | ||
| 79 | (should (eq (char-after 2) ?a)) | ||
| 80 | (should (eq (point-max) 3)))))) | ||
| 81 | (delete-fn | ||
| 82 | (lambda (zip-nonempty) | ||
| 83 | (with-current-buffer (find-file-noselect zip-nonempty) | ||
| 84 | ;; mark delete and expunge first entry | ||
| 85 | (save-excursion | ||
| 86 | (goto-char archive-file-list-start) | ||
| 87 | (should (length= archive-files 2)) | ||
| 88 | (archive-flag-deleted 1) | ||
| 89 | (archive--expunge-maybe-force t) | ||
| 90 | (should (length= archive-files 1)))))) | ||
| 91 | (test-modify | ||
| 92 | (lambda (zip mod-fn) | ||
| 93 | (let ((zip-base (concat zip ".zip")) | ||
| 94 | (tag (gensym))) | ||
| 95 | (copy-file base-zip-1 zip t) | ||
| 96 | (copy-file base-zip-2 zip-base t) | ||
| 97 | (file-has-changed-p zip tag) | ||
| 98 | (file-has-changed-p zip-base tag) | ||
| 99 | (funcall mod-fn zip) | ||
| 100 | (should-not (file-has-changed-p zip-base tag)) | ||
| 101 | (should (file-has-changed-p zip tag)))))) | ||
| 102 | ;; setup: make two zip files with different contents | ||
| 103 | (mapc make-file (append content-1 content-2)) | ||
| 104 | (mapc (lambda (args) (apply make-zip args)) | ||
| 105 | (list (list base-zip-1 content-1) | ||
| 106 | (list base-zip-2 content-2))) | ||
| 107 | ;; test 1: with "test-update" and "test-update.zip", update | ||
| 108 | ;; "test-update": (1) ensure only "test-update" is modified, (2) | ||
| 109 | ;; ensure the contents of the new member is expected. | ||
| 110 | (funcall test-modify "test-update" update-fn) | ||
| 111 | ;; test 2: with "test-delete" and "test-delete.zip", delete entry | ||
| 112 | ;; from "test-delete": (1) ensure only "test-delete" is modified, | ||
| 113 | ;; (2) ensure the file list is reduced as expected. | ||
| 114 | (funcall test-modify "test-delete" delete-fn))) | ||
| 115 | |||
| 49 | (provide 'arc-mode-tests) | 116 | (provide 'arc-mode-tests) |
| 50 | 117 | ||
| 51 | ;;; arc-mode-tests.el ends here | 118 | ;;; arc-mode-tests.el ends here |