From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61326: [DRAFT PATCH] Work around zip's filename extension limitation (was: Adding --no-add-suffix to zip patch) Date: Thu, 09 Feb 2023 00:48:15 +0800 Message-ID: References: <87ilgeoc4w.fsf@tullinup.koldfront.dk> <8574C128-9560-490A-88E6-49E415BBDB24@netyu.xyz> <83k00up32i.fsf@gnu.org> Reply-To: Ruijie Yu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13891"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.13; emacs 29.0.60 Cc: Eli Zaretskii , asjo@koldfront.dk To: 61326@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 08 18:03:12 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPnqh-0003ON-Jz for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Feb 2023 18:03:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPnoy-0002Wz-J9; Wed, 08 Feb 2023 12:01:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPnoc-0002J3-VZ for bug-gnu-emacs@gnu.org; Wed, 08 Feb 2023 12:01:08 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pPnoc-0002bJ-Jx for bug-gnu-emacs@gnu.org; Wed, 08 Feb 2023 12:01:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pPnoc-0005rS-1i for bug-gnu-emacs@gnu.org; Wed, 08 Feb 2023 12:01:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ruijie Yu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Feb 2023 17:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61326 X-GNU-PR-Package: emacs Original-Received: via spool by 61326-submit@debbugs.gnu.org id=B61326.167587561722472 (code B ref 61326); Wed, 08 Feb 2023 17:01:02 +0000 Original-Received: (at 61326) by debbugs.gnu.org; 8 Feb 2023 17:00:17 +0000 Original-Received: from localhost ([127.0.0.1]:56505 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pPnns-0005qM-N9 for submit@debbugs.gnu.org; Wed, 08 Feb 2023 12:00:17 -0500 Original-Received: from netyu.xyz ([152.44.41.246]:36430 helo=mail.netyu.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pPnnn-0005q6-HZ for 61326@debbugs.gnu.org; Wed, 08 Feb 2023 12:00:15 -0500 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id e6b2930e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 8 Feb 2023 17:00:08 +0000 (UTC) In-reply-to: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:255154 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text edit= ors" writes: > Eli Zaretskii writes: > >>> Cc: 61326@debbugs.gnu.org >>> Date: Tue, 7 Feb 2023 09:31:11 +0800 >>> From: Ruijie Yu via "Bug reports for GNU Emacs, >>> the Swiss army knife of text editors" >>> >>> Maybe, at least in the meantime, we change it such that all write opera= tions >>> for zip create files in temp, and move to / overwrite the original file= when >>> done? Although I don=E2=80=99t have a full understanding on how that wo= uld be done and >>> whether there are problems along with it. >> >> How about submitting a patch to do that, but only when the original >> file doesn't have an extension? > > Will do. Will report back in 2-3 days unless someone else gets to it > first. > > Best, > > > RY Here is a preliminary patch that contains some "REVIEW" comments where I need inputs. I have tested with the following recipe and things seem to work correctly: $ touch 1 2 && zip z 1 2 && mv z.zip z $ ls -l .... 1 .... 2 .... z $ src/emacs -Q RET ; open file "1" from within "z" archive s C-x C-s ; insert "s" and save file "1" C-x C-c ; exit $ ls -l # notice that no "z.zip" exists, and "z" is correctly updated .... 1 .... 2 .... z Patch based on 907fd1f7ff402f9d226ebb3b891ea5b54fac1d1c which is ~3 days old. I will amend the commit (and rebase if necessary) according to ML reviews and further progress. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-arc-mode.el-Work-around-zip-s-filename-limitati.patch >From bc086395929520a66eb928fd5d3baf6c9fa79bb5 Mon Sep 17 00:00:00 2001 From: Ruijie Yu Date: Thu, 9 Feb 2023 00:45:19 +0800 Subject: [PATCH] lisp/arc-mode.el Work around zip's filename limitations on extension [DRAFT PATCH] Fixes 61326. The "zip" executable requires that the named archive must have an extension, else it attaches ".zip" to the supplied file name, causing incorrect behaviors. This patch looks for such scenarios and temporarily rename extension-less archives so that "zip" would function correctly. TODO: 1. Address all REVIEW points. 2. Make sure other write operations, in addition to zip-write-member, are fixed. 3. Tests? (I might need some pointers as to where existing tests are and how to write them.) --- lisp/arc-mode.el | 82 +++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 6f3e922880d..ac8c7cefa89 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -1350,42 +1350,61 @@ archive-write-file-member (setq last-coding-system-used archive-member-coding-system)) t) -(defun archive-*-write-file-member (archive descr command) +;; REVIEW: is there a better name than AVOID-EXTLESS-P? +(defun archive-*-write-file-member (archive descr command + &optional avoid-extless-p) (let* ((archive (expand-file-name archive)) (ename (archive--file-desc-ext-file-name descr)) (tmpfile (expand-file-name ename archive-tmpdir)) (top (directory-file-name (file-name-as-directory archive-tmpdir))) (default-directory (file-name-as-directory top))) + ;; REVIEW: the diff here is because the previous code had TAB's + ;; (while assuming each TAB is 4 spaces), and my Emacs replaced + ;; them with spaces. What is the status quo on this kind of diff? + ;; I can remove them if we consider this change excessive and/or + ;; intrusive. (unwind-protect (progn (make-directory (file-name-directory tmpfile) t) - ;; If the member is itself an archive, write it without - ;; the dired-like listing we created. - (if (eq major-mode 'archive-mode) - (archive-write-file tmpfile) - (write-region nil nil tmpfile nil 'nomessage)) - ;; basic-save-buffer needs last-coding-system-used to have - ;; the value used to write the file, so save it before any - ;; further processing clobbers it (we restore it in - ;; archive-write-file-member, above). - (setq archive-member-coding-system last-coding-system-used) - (if (archive--file-desc-mode descr) - ;; Set the file modes, but make sure we can read it. - (set-file-modes tmpfile - (logior ?\400 (archive--file-desc-mode descr)))) - (setq ename - (encode-coding-string ename archive-file-name-coding-system)) + ;; If the member is itself an archive, write it without + ;; the dired-like listing we created. + (if (eq major-mode 'archive-mode) + (archive-write-file tmpfile) + (write-region nil nil tmpfile nil 'nomessage)) + ;; basic-save-buffer needs last-coding-system-used to have + ;; the value used to write the file, so save it before any + ;; further processing clobbers it (we restore it in + ;; archive-write-file-member, above). + (setq archive-member-coding-system last-coding-system-used) + (if (archive--file-desc-mode descr) + ;; Set the file modes, but make sure we can read it. + (set-file-modes tmpfile + (logior ?\400 (archive--file-desc-mode descr)))) + (setq ename + (encode-coding-string ename archive-file-name-coding-system)) (let* ((coding-system-for-write 'no-conversion) - (default-directory (file-name-as-directory archive-tmpdir)) - (exitcode (apply #'call-process - (car command) - nil - nil - nil - (append (cdr command) - (list archive ename))))) - (or (zerop exitcode) - (error "Updating was unsuccessful (%S)" exitcode)))) + (default-directory (file-name-as-directory archive-tmpdir)) + (safe-archive + (if avoid-extless-p + (make-temp-name + (expand-file-name (concat archive "_tmp."))) + archive)) + (maybe-rename + (lambda (newname) + (when avoid-extless-p + (with-current-buffer archive-superior-buffer + (rename-visited-file newname)))))) + ;; REVIEW: is `unwind-protect' necessary here? + (prog2 (funcall maybe-rename safe-archive) + (let ((exitcode + (apply #'call-process (car command) + nil nil nil + (append (cdr command) + (list safe-archive ename))))) + (or (zerop exitcode) + (error "Updating was unsuccessful (%S)" + exitcode))) + (funcall maybe-rename archive)))) (archive-delete-local tmpfile)))) (defun archive-write-file (&optional file) @@ -2048,12 +2067,19 @@ archive--file-desc-case-fiddled (not (eq (archive--file-desc-int-file-name fd) (archive--file-desc-ext-file-name fd)))) +(defun archive--file-name-zip-extless-p (fname) + ;; zip's rule: if the filename contains "." anywhere in the name + ;; (including obscure names like ".foo" and "bar."), then this + ;; filename is considered to have an extension. + (not (seq-contains-p (file-name-nondirectory fname) ?. #'eq))) + (defun archive-zip-write-file-member (archive descr) (archive-*-write-file-member archive descr (if (archive--file-desc-case-fiddled descr) - archive-zip-update-case archive-zip-update))) + archive-zip-update-case archive-zip-update) + (archive--file-name-zip-extless-p archive))) (defun archive-zip-chmod-entry (newmode files) (save-restriction -- 2.39.1 --=-=-= Content-Type: text/plain Best, RY --=-=-=--