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 v2] Work around zip's filename extension limitation (was: Adding --no-add-suffix to zip patch) Date: Fri, 10 Feb 2023 16:40:25 +0800 Message-ID: References: <87ilgeoc4w.fsf@tullinup.koldfront.dk> <8574C128-9560-490A-88E6-49E415BBDB24@netyu.xyz> <83k00up32i.fsf@gnu.org> <83bkm4nihw.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="1051"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.13; emacs 29.0.60 Cc: asjo@koldfront.dk, 61326@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 10 10:35:24 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 1pQPoS-000Abw-DI for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 Feb 2023 10:35:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQPoE-0000Xn-9J; Fri, 10 Feb 2023 04:35:10 -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 1pQPo7-0000Vs-RI for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2023 04:35:04 -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 1pQPo7-0001oF-BT for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2023 04:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pQPo6-0003AQ-9o for bug-gnu-emacs@gnu.org; Fri, 10 Feb 2023 04:35: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: Fri, 10 Feb 2023 09:35: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.167602170112170 (code B ref 61326); Fri, 10 Feb 2023 09:35:02 +0000 Original-Received: (at 61326) by debbugs.gnu.org; 10 Feb 2023 09:35:01 +0000 Original-Received: from localhost ([127.0.0.1]:34353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQPo5-0003A8-3K for submit@debbugs.gnu.org; Fri, 10 Feb 2023 04:35:01 -0500 Original-Received: from netyu.xyz ([152.44.41.246]:48376 helo=mail.netyu.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQPo2-00039y-HU for 61326@debbugs.gnu.org; Fri, 10 Feb 2023 04:35:00 -0500 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id 14780955 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 Feb 2023 09:34:55 +0000 (UTC) In-reply-to: <83bkm4nihw.fsf@gnu.org> 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:255284 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Ruijie Yu >> Cc: Eli Zaretskii , asjo@koldfront.dk >> Date: Thu, 09 Feb 2023 00:48:15 +0800 >> >> Here is a preliminary patch that contains some "REVIEW" comments where I >> need inputs. > > Thanks, but could you perhaps post diffs disregarding the whitespace > changes? That would make it easier to review the real changes. Thanks, done. >> -(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) > > ensure-extension? That sounds better, and I have renamed the variable in this iteration. >> + ;; 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. > > TABs in Emacs are by default 8 columns, not 4. > > It is OK to convert TABs to spaces when changing the code in Lisp, but > please do that only for the last commit, to make the review process > easier. For all the draft versions, please use "git diff" options > that cause Git to ignore changes in whitespace. > > Thanks. Thanks, I will keep that in mind. I have also made some rearrangements in the code to minimize delta. In addition, I fixed an issue from the first iteration: in the first iteration, the user would be prompted to revert buffer from disk if the rename was in action; in this iteration this should no longer be the case -- that is, the user should expect no difference between filenames with extensions and without. As pointed out in the commit message, two things remain: to ensure that all write operations to extensionless zip archives behave correctly, and to have some way to test that things continue to work in the future. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-arc-mode.el-Work-around-zip-s-filename-limitati.patch >From bc56c17082ea3ff2a76308f14310908853e3a2d1 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. Make sure other write operations, in addition to zip-write-member, are fixed. 2. Tests? (I might need some pointers as to where existing tests are and how to write them.) --- lisp/arc-mode.el | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 6f3e922880d..cd7f4ca1134 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -1350,14 +1350,23 @@ archive-write-file-member (setq last-coding-system-used archive-member-coding-system)) t) -(defun archive-*-write-file-member (archive descr command) +(defun archive-*-write-file-member + (archive descr command &optional ensure-extension) (let* ((archive (expand-file-name archive)) + (real-archive archive) + (archive (if ensure-extension + (make-temp-name + (expand-file-name (concat archive "_tmp."))) + 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))) (unwind-protect - (progn + (cl-flet ((maybe-rename (newname) + (when ensure-extension + (with-current-buffer archive-superior-buffer + (rename-visited-file newname))))) (make-directory (file-name-directory tmpfile) t) ;; If the member is itself an archive, write it without ;; the dired-like listing we created. @@ -1376,16 +1385,20 @@ archive-*-write-file-member (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 + (default-directory (file-name-as-directory archive-tmpdir))) + (unwind-protect + (progn + (maybe-rename archive) + (let ((exitcode + (apply #'call-process (car command) + nil nil nil (append (cdr command) (list archive ename))))) (or (zerop exitcode) (error "Updating was unsuccessful (%S)" exitcode)))) + (progn (maybe-rename real-archive) + (with-current-buffer archive-superior-buffer + (revert-buffer nil t)))))) (archive-delete-local tmpfile)))) (defun archive-write-file (&optional file) @@ -2048,12 +2061,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 --=-=-=--