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 v3] Work around zip's filename extension limitation (was: Adding --no-add-suffix to zip patch) Date: Mon, 13 Feb 2023 18:35:17 +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="28093"; 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 Mon Feb 13 12:16:22 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 1pRWon-000707-Tv for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 13 Feb 2023 12:16:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRWoX-0003Nl-Bk; Mon, 13 Feb 2023 06:16:05 -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 1pRWoV-0003NJ-2D for bug-gnu-emacs@gnu.org; Mon, 13 Feb 2023 06:16:03 -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 1pRWoU-00075g-Ly for bug-gnu-emacs@gnu.org; Mon, 13 Feb 2023 06:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pRWoU-0003jb-4c for bug-gnu-emacs@gnu.org; Mon, 13 Feb 2023 06:16: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: Mon, 13 Feb 2023 11:16: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.167628691814298 (code B ref 61326); Mon, 13 Feb 2023 11:16:02 +0000 Original-Received: (at 61326) by debbugs.gnu.org; 13 Feb 2023 11:15:18 +0000 Original-Received: from localhost ([127.0.0.1]:47791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pRWnl-0003iY-H5 for submit@debbugs.gnu.org; Mon, 13 Feb 2023 06:15:17 -0500 Original-Received: from netyu.xyz ([152.44.41.246]:59672 helo=mail.netyu.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pRWnj-0003iP-Oh for 61326@debbugs.gnu.org; Mon, 13 Feb 2023 06:15:16 -0500 Original-Received: from fw.net.yu.netyu.xyz ( [222.248.4.98]) by netyu.xyz (OpenSMTPD) with ESMTPSA id 592b1d27 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 13 Feb 2023 11:15:14 +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:255480 Archived-At: --=-=-= Content-Type: text/plain I believe the functionalities (both update and deletion) are done in this patch. I have not added any tests nor updates on documentation, as I am not sure what and where they should be. I have done some basic tests locally to confirm that it works: - update subfile in a zip archive named "z" - delete subfile in a zip archive named "z" - update subfile in a zip archive named "x.zip" - delete subfile in a zip archive named "x.zip" FTR, if this is of any importance: the filesystem containing the archives "z" and "x.zip" is btrfs, and /tmp is ext2 on zram. Not sure if any problems would arise in other filesystems / OSes -- hopefully someone else on those platforms can confirm that it works. Comments welcome. Particularly on my choices of naming. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-arc-mode.el-Work-around-zip-s-filename-limitati.patch >From 0766bec8071c7c793d6c81211577832d9a7a78f9 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. Currently there are no tests. I might need some pointers as to where existing tests are and how to write them. --- lisp/arc-mode.el | 64 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 6f3e922880d..875b3971086 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el @@ -645,6 +645,49 @@ archive-get-descr (if (not noerror) (error "Line does not describe a member of the archive"))))) ;; ------------------------------------------------------------------------- +;;; Section: Helper functions for requiring filename extensions + +(defun archive--act-files (command files) + (lambda (archive) + (apply #'call-process (car command) + nil nil nil (append (cdr command) (cons archive files))))) + +(defun archive--need-rename-p (&optional archive) + (let ((archive + (file-name-nondirectory (or archive buffer-file-name)))) + (cl-case archive-subtype + ((zip) (not (seq-contains-p archive ?. #'eq)))))) + +(defun archive--ensure-extension (archive ensure-extension) + (if ensure-extension + (make-temp-name (expand-file-name (concat archive "_tmp."))) + archive)) + +(defun archive--maybe-rename (newname need-rename-p) + ;; Operating with archive as current buffer, and protect + ;; `default-directory' from being modified in `rename-visited-file'. + (when need-rename-p + (let ((default-directory default-directory)) + (rename-visited-file newname)))) + +(defun archive--with-ensure-extension (archive proc-fn) + (let ((saved default-directory)) + (with-current-buffer (find-buffer-visiting archive) + (let ((ensure-extension (archive--need-rename-p)) + (default-directory saved)) + (unwind-protect + ;; Some archive programs (like zip) expect filenames to + ;; have an extension, so if necessary, temporarily rename + ;; an extensionless file for write accesses. + (let ((archive (archive--ensure-extension + archive ensure-extension))) + (archive--maybe-rename archive ensure-extension) + (let ((exitcode (funcall proc-fn archive))) + (or (zerop exitcode) + (error "Updating was unsuccessful (%S)" exitcode)))) + (progn (archive--maybe-rename archive ensure-extension) + (revert-buffer nil t))))))) +;; ------------------------------------------------------------------------- ;;; Section: the mode definition ;;;###autoload @@ -1376,16 +1419,9 @@ 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 - (append (cdr command) - (list archive ename))))) - (or (zerop exitcode) - (error "Updating was unsuccessful (%S)" exitcode)))) + (default-directory (file-name-as-directory archive-tmpdir))) + (archive--with-ensure-extension + archive (archive--act-files command (list ename))))) (archive-delete-local tmpfile)))) (defun archive-write-file (&optional file) @@ -1539,12 +1575,8 @@ archive-expunge (revert-buffer)))))) (defun archive-*-expunge (archive files command) - (apply #'call-process - (car command) - nil - nil - nil - (append (cdr command) (cons archive files)))) + (archive--with-ensure-extension + archive (archive--act-files command files))) (defun archive-rename-entry (newname) "Change the name associated with this entry in the archive file." -- 2.39.1 --=-=-= Content-Type: text/plain -- Best, RY --=-=-=--