emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 157a91b54be: Fix decoding non-ASCII file names in zip archives


From: Eli Zaretskii
Subject: emacs-29 157a91b54be: Fix decoding non-ASCII file names in zip archives on MS-Windows
Date: Sat, 11 Mar 2023 06:32:48 -0500 (EST)

branch: emacs-29
commit 157a91b54bece12d197ad66c756dcea7d1679a54
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix decoding non-ASCII file names in zip archives on MS-Windows
    
    * lisp/arc-mode.el (archive-zip-summarize): On MS-Windows,
    override archive-file-name-coding-system for files compressed
    on MS-Windows, and use the local console encoding instead.
---
 lisp/arc-mode.el | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index dcf7c17a878..41b239fbef9 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -1960,6 +1960,16 @@ This doesn't recover lost files, it just undoes changes 
in the buffer itself."
   (goto-char (- (point-max) (- 22 18)))
   (search-backward-regexp "[P]K\005\006")
   (let ((p (archive-l-e (+ (point) 16) 4))
+        (w32-fname-encoding
+         ;; On MS-Windows, both InfoZip's Zip and the system's
+         ;; built-in File Explorer use the console codepage for
+         ;; encoding file names.  Problem: the codepage of the system
+         ;; where the zip file was created cannot be known; we assume
+         ;; it is the same as the one of the current system.  Also,
+         ;; the zip file doesn't tell us the OS where the file was
+         ;; created, it only tells the filesystem.
+         (if (eq system-type 'windows-nt)
+             (intern (format "cp%d" (w32-get-console-codepage)))))
         files)
     (when (or (= p #xffffffff) (= p -1))
       ;; If the offset of end-of-central-directory is 0xFFFFFFFF, this
@@ -1989,7 +1999,15 @@ This doesn't recover lost files, it just undoes changes 
in the buffer itself."
              ;; (lheader (archive-l-e (+ p 42) 4))
              (efnname (let ((str (buffer-substring (+ p 46) (+ p 46 fnlen))))
                        (decode-coding-string
-                        str archive-file-name-coding-system)))
+                        str
+                         (or (if (and w32-fname-encoding
+                                      (memq creator
+                                            ;; This should be just 10 and
+                                            ;; 14, but InfoZip uses 0 and
+                                            ;; File Explorer uses 11(??).
+                                            '(0 10 11 14)))
+                                 w32-fname-encoding)
+                             archive-file-name-coding-system))))
              (ucsize  (if (and (or (= ucsize #xffffffff) (= ucsize -1))
                                (> exlen 0))
                           ;; APPNOTE.TXT, para 4.5.3: the Extra Field



reply via email to

[Prev in Thread] Current Thread [Next in Thread]