emacs-devel
[Top][All Lists]
Advanced

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

Re: archive-mode lzh filename fiddling problems (patch)


From: Richard Stallman
Subject: Re: archive-mode lzh filename fiddling problems (patch)
Date: Mon, 16 Apr 2007 00:32:15 -0400

Would someone else please look at this patch
to verify it is fully correct?


From: Kevin Ryde <address@hidden>
To: address@hidden
Date: Sun, 15 Apr 2007 08:02:55 +1000
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Subject: archive-mode lzh filename fiddling problems (patch)

--=-=-=

In tinkering with some lzh archives I noticed two apparent problems
with the filename downcasing done by archive-lzh-summarize.

First, on an archive created by the lha for unix program, a file with
an all uppercase name only produces an empty buffer when viewed.  Eg.

        echo hi >README
        lha a foo.lzh README
        emacs -Q foo.lzh
        Ret
        => empty buffer

where I hoped to see "hi".  Only upper case filenames seem affected,
you can see "Readme" or "readme" ok.

Second, on an archive file of "MS-DOS" type but with a mixed-case
name, viewing the member similarly produces an empty buffer.  I
noticed this on some downloaded self-extracting exes (which might come
from w32, if someone has that obscure system to try directly).  Eg.

        wget http://kanex.or.jp/history/BRO07.exe
        dd ibs=1 skip=30720 <BRO07.exe >BRO07.lzh
        emacs -Q BRO07.lzh
        Ret
        => empty buffer

where I hoped to see the price of chicken futures.  You can also
change the .exe to .lzh by adding something to the archive, if you
don't trust dd.  Eg.

        lha a BRO07.exe /etc/passwd
        => writes BRO07.lzh

Either way the .csv file in the archive isn't empty, you can see it
with the following.  (The contents are shift-jis, I don't think that
affects anything.)

        lha pq BRO07.lzh bro07.csv


I believe archive-lzh-summarize has to follow the lha program's
up/down casing, because that munged form is what it expects on the
command line when asked for an "lha pq" extract etc, as done by
archive-mode.  I get some joy from the change below.

For exercising the cases, lha for unix produces level 1 type U (unix)
archives, or with the g flag produces level 0 (generic, and upcase
names).  The broilers download above is level 2 type M (msdos) with
mixed case name.  And I tried some level 0 (generic) with mixed case
names from kanex which are no longer available for download.


2007-04-14  Kevin Ryde  <address@hidden>

        * arc-mode.el (archive-lzh-summarize): Two fixes to filename fiddling.

        Only apply the "downcase if all upcase" rule to OS-ID 0 "generic".
        This fixes extracting of upper case files like "README" from archives
        created on unix (such filenames should be left alone).

        Alwyas apply a downcase to OS-ID M "MSDOS".  This fixes extracting of
        mixed-case filenames from archives apparently created on w32 systems,
        eg. http://kanex.or.jp/history/BR07.exe (delete the first 30720 bytes
        of self-extracting code to make a .lzh).


--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment; filename=arc-mode.el.lzh-filename-fiddle.diff

*** arc-mode.el 12 Mar 2007 10:14:18 +1100      1.79
--- arc-mode.el 14 Apr 2007 19:13:53 +1000      
***************
*** 1415,1421 ****
             (time2   (archive-l-e (+ p 17) 2)) ;and UNIX format in level 2 
header.)
             (hdrlvl  (char-after (+ p 20))) ;header level
             thsize             ;total header size (base + extensions)
!            fnlen efnname fiddle ifnname width p2
             neh        ;beginning of next extension header (level 1 and 2)
             mode modestr uid gid text dir prname
             gname uname modtime moddate)
--- 1415,1421 ----
             (time2   (archive-l-e (+ p 17) 2)) ;and UNIX format in level 2 
header.)
             (hdrlvl  (char-after (+ p 20))) ;header level
             thsize             ;total header size (base + extensions)
!            fnlen efnname osid fiddle ifnname width p2
             neh        ;beginning of next extension header (level 1 and 2)
             mode modestr uid gid text dir prname
             gname uname modtime moddate)
***************
*** 1474,1480 ****
              (setq thsize (- neh p))))
        (if (= hdrlvl 0)  ;total header size
            (setq thsize hsize))
!       (setq fiddle  (if efnname (string= efnname (upcase efnname))))
        (setq ifnname (if fiddle (downcase efnname) efnname))
        (setq prname (if dir (concat dir ifnname) ifnname))
        (setq width (if prname (string-width prname) 0))
--- 1474,1495 ----
              (setq thsize (- neh p))))
        (if (= hdrlvl 0)  ;total header size
            (setq thsize hsize))
!         ;; OS ID field not present in level 0 header, use code 0 "generic"
!         ;; in that case as per lha program header.c get_header()
!       (setq osid (cond ((= hdrlvl 0)  0)
!                          ((= hdrlvl 1)  (char-after (+ p 22 fnlen 2)))
!                          ((= hdrlvl 2)  (char-after (+ p 23)))))
!         ;; Filename fiddling must follow the lha program, otherwise the name
!         ;; passed to "lha pq" etc won't match (which for an extract silently
!         ;; results in no output).  As of version 1.14i it goes from the OS ID,
!         ;; - For 'M' MSDOS: msdos_to_unix_filename() downcases always, and
!         ;;   converts "\" to "/".
!         ;; - For 0 generic: generic_to_unix_filename() downcases if there's
!         ;;   no lower case already present, and converts "\" to "/".
!         ;; - For 'm' MacOS: macos_to_unix_filename() changes "/" to ":" and
!         ;;   ":" to "/"
!       (setq fiddle (cond ((= ?M osid) t)
!                            ((= 0 osid)  (string= efnname (upcase efnname)))))
        (setq ifnname (if fiddle (downcase efnname) efnname))
        (setq prname (if dir (concat dir ifnname) ifnname))
        (setq width (if prname (string-width prname) 0))

--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Emacs-devel mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-devel
--=-=-=--







reply via email to

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