all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: asjo@koldfront.dk, 61326@debbugs.gnu.org
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	[thread overview]
Message-ID: <sdvr0uxoocn.fsf@fw.net.yu> (raw)
In-Reply-To: <83bkm4nihw.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Ruijie Yu <ruijie@netyu.xyz>
>> Cc: Eli Zaretskii <eliz@gnu.org>, 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-arc-mode.el-Work-around-zip-s-filename-limitati.patch --]
[-- Type: text/x-patch, Size: 4186 bytes --]

From bc56c17082ea3ff2a76308f14310908853e3a2d1 Mon Sep 17 00:00:00 2001
From: Ruijie Yu <ruijie+git@netyu.xyz>
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


[-- Attachment #3: Type: text/plain, Size: 12 bytes --]


Best,


RY

  reply	other threads:[~2023-02-10  8:40 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 17:00 bug#61326: 30.0.50; Editing fil in zip file without extension save creates new file Adam Sjøgren via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-06 18:04 ` Eli Zaretskii
2023-02-06 18:15   ` Adam Sjøgren via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-06 18:57 ` bug#61326: Adding --no-add-suffix to zip patch Adam Sjøgren via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-07  1:31   ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-07  3:27     ` Eli Zaretskii
2023-02-07 13:53       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-07 14:54         ` Eli Zaretskii
2023-02-08 16:48         ` bug#61326: [DRAFT PATCH] Work around zip's filename extension limitation (was: Adding --no-add-suffix to zip patch) Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-08 18:02           ` Eli Zaretskii
2023-02-10  8:40             ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-02-13 10:35               ` bug#61326: [DRAFT PATCH v3] " Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-04 11:21                 ` Eli Zaretskii
2023-03-04 14:56                   ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-04 15:12                     ` Eli Zaretskii
2023-03-05 15:23                       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-05 15:52                         ` Eli Zaretskii
2023-03-06  4:05                           ` bug#61326: [DRAFT PATCH v4] " Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-11  8:54                             ` Eli Zaretskii
2023-03-11  8:57                               ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-17  3:19                                 ` bug#61326: [DRAFT PATCH v5] " Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-17  8:48                                   ` bug#61326: [PATCH " Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-20  7:47                                     ` Eli Zaretskii
2023-04-20  8:49                                       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-20  9:29                                         ` Eli Zaretskii
2023-02-07 19:59     ` bug#61326: Adding --no-add-suffix to zip patch Adam Sjøgren via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-08  1:21       ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-08  3:28         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sdvr0uxoocn.fsf@fw.net.yu \
    --to=bug-gnu-emacs@gnu.org \
    --cc=61326@debbugs.gnu.org \
    --cc=asjo@koldfront.dk \
    --cc=eliz@gnu.org \
    --cc=ruijie@netyu.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.