Loading ...
Sorry, an error occurred while loading the content.
 

Bug report: Zip file reading breaks with zip comments.

Expand Messages
  • Kevin Goodsell
    Opening a zip file with Vim doesn t work properly if the zip file includes a comment. For example, create a zip file this way: $ touch foo.txt $ zip -z foo.zip
    Message 1 of 2 , Jan 12, 2011
      Opening a zip file with Vim doesn't work properly if the zip file
      includes a comment. For example, create a zip file this way:

      $ touch foo.txt
      $ zip -z foo.zip foo.txt
      adding: foo.txt (stored 0%)
      enter new zip file comment (end with .):
      Comment!
      .

      When opening this zip, the file list will be displayed differently,
      and opening a file will fail with the cryptic error "caution: filename
      not matched".

      The problem comes from the zip#Browse() function in autoload/zip.vim.
      Once the zip contents have been listed with "unzip -l --
      archive-name", It does the following:

      let namecol= stridx(getline(6),'Name') + 1

      Note that it expects to find 'Name' (the column header for the zip
      listing) on line six. This works fine if there is no comment, because
      the listing begins on line five of the buffer and the headers appear
      on the second line of the listing. However, when a comment is present
      unzip -l includes the comment before the headers, and the headers will
      instead be on some line after line six. This causes the lines of the
      listing to be left as-is, with file size and time information, rather
      than being stripped down to just the name. When one of these lines is
      selected, it is assumed that the length and time are part of the name,
      but no file with that name can be located in the zip.

      Here is a possible patch. I tried to simplify things a bit, using :d
      with line numbers instead of :g with pattens. I also left the cursor
      at the first file in the list, which seems nicer to me. This would
      clearly not work with a localized version of zip that used non-English
      names for the headers, but then neither does the original version.

      This is based on a slightly older version of zip.vim, but there are no
      relevant changes in the current version. The patch should apply
      cleanly.

      -Kevin

      --- /usr/share/vim/vim72/autoload/zip.vim 2009-09-21 04:22:52.000000000 -0700
      +++ zip.vim 2010-12-23 17:37:00.000000000 -0800
      @@ -121,14 +121,15 @@
      return
      endif
      " call Decho("line 6: ".getline(6))
      - let namecol= stridx(getline(6),'Name') + 1
      + 1
      + let [headerline, namecol] =
      searchpos('\v^\s*Length\s*Date\s*Time\s*\zsName\s*$')
      " call Decho("namecol=".namecol)
      - 4,$g/^\s*----/d
      - 4,$g/^\s*\a/d
      - $d
      + exec printf("5,%dd", headerline+1)
      + $-1,$d
      if namecol > 0
      exe 'silent 4,$s/^.*\%'.namecol.'c//'
      endif
      + 5

      setlocal noma nomod ro
      noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Charles Campbell
      ... Hello! I realize that this report is over a year old; I m going through my old email and saw this. Perhaps the most recent zip.vim already handles this?
      Message 2 of 2 , Mar 26, 2012
        Kevin Goodsell wrote:
        > Opening a zip file with Vim doesn't work properly if the zip file
        > includes a comment. For example, create a zip file this way:
        >
        > $ touch foo.txt
        > $ zip -z foo.zip foo.txt
        > adding: foo.txt (stored 0%)
        > enter new zip file comment (end with .):
        > Comment!
        > .
        >
        > When opening this zip, the file list will be displayed differently,
        > and opening a file will fail with the cryptic error "caution: filename
        > not matched".
        >
        > The problem comes from the zip#Browse() function in autoload/zip.vim.
        > Once the zip contents have been listed with "unzip -l --
        > archive-name", It does the following:
        >
        > let namecol= stridx(getline(6),'Name') + 1
        >
        > Note that it expects to find 'Name' (the column header for the zip
        > listing) on line six. This works fine if there is no comment, because
        > the listing begins on line five of the buffer and the headers appear
        > on the second line of the listing. However, when a comment is present
        > unzip -l includes the comment before the headers, and the headers will
        > instead be on some line after line six. This causes the lines of the
        > listing to be left as-is, with file size and time information, rather
        > than being stripped down to just the name. When one of these lines is
        > selected, it is assumed that the length and time are part of the name,
        > but no file with that name can be located in the zip.
        >
        > Here is a possible patch. I tried to simplify things a bit, using :d
        > with line numbers instead of :g with pattens. I also left the cursor
        > at the first file in the list, which seems nicer to me. This would
        > clearly not work with a localized version of zip that used non-English
        > names for the headers, but then neither does the original version.
        >
        > This is based on a slightly older version of zip.vim, but there are no
        > relevant changes in the current version. The patch should apply
        > cleanly.
        >
        > -Kevin
        >
        > --- /usr/share/vim/vim72/autoload/zip.vim 2009-09-21 04:22:52.000000000 -0700
        > +++ zip.vim 2010-12-23 17:37:00.000000000 -0800
        > @@ -121,14 +121,15 @@
        > return
        > endif
        > " call Decho("line 6: ".getline(6))
        > - let namecol= stridx(getline(6),'Name') + 1
        > + 1
        > + let [headerline, namecol] =
        > searchpos('\v^\s*Length\s*Date\s*Time\s*\zsName\s*$')
        > " call Decho("namecol=".namecol)
        > - 4,$g/^\s*----/d
        > - 4,$g/^\s*\a/d
        > - $d
        > + exec printf("5,%dd", headerline+1)
        > + $-1,$d
        > if namecol> 0
        > exe 'silent 4,$s/^.*\%'.namecol.'c//'
        > endif
        > + 5
        >
        > setlocal noma nomod ro
        > noremap<silent> <buffer> <cr> :call<SID>ZipBrowseSelect()<cr>
        >
        >
        Hello!

        I realize that this report is over a year old; I'm going through my old
        email and saw this.

        Perhaps the most recent zip.vim already handles this? Please try v25 of
        zip.vim (http://www.drchip.org/astronaut/vim/index.html#ZIP).
        OTOH, its quite possible that I've already discussed this with you back
        when but didn't take your email off the hasn't-handled list.

        Regards,
        Chip Campbell

        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      Your message has been successfully submitted and would be delivered to recipients shortly.