To Reproduce
Detailed steps to reproduce the behavior:
vim xxx.zip~/.../zipfile:/.../xxx.zip:xxx.txt, i.e. with current directory prepended.Expected behavior
netrw should read the zipped xxx.txt's content into new buffer.
Environment (please complete the following information):
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
looks it's not related to 'netrw' but 'zip.vim', though same auther: @cecamp
// looks 'zip.vim' was not a complete runtime, it set ft of zip to 'tar' also?!......
That is odd. It was working when I was working with an earlier version of vim, then it stopped working when I myself updated vim. I keep a copy of my plugins separate from vim, so they're not affected by updates. I see what Shane means; opening the zip file shows a filetype of tar, not zip. Putting a line into my own filetype.vim such as
au BufNewFile,BufReadPost *.zip setf zip
still leaves *.zip files being recognized as *.tar files. I don't think this has anything to do with something that I did.
Hm, the tar filetype come from this line in the plugin:
https://github.com/vim/vim/blob/master/runtime/autoload/zip.vim#L118
I don't think this is correct. For the other issue, let me have a quick look
Okay, so how about the following patch. It checks, whether the filename starts with something that looks like a protocol specifier like http:/ or in this case zipfile:/ and in that case does not prepend the current directory to it (assuming a plugin will take care of reading this):
diff --git a/src/os_unix.c b/src/os_unix.c index d192b6bcf..09e1f7d2f 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2648,11 +2648,17 @@ mch_FullName( vim_strncpy(buf, fname, p - fname); if (mch_chdir((char *)buf)) { + char_u *s = vim_strchr(fname, ':'); + // Path does not exist (yet). For a full path fail, // will use the path as-is. For a relative path use // the current directory and append the file name. if (mch_isFullName(fname)) retval = FAIL; + // the filename begins with a protocol identifier like http:// + // do not prepend the path to it, a plugin may handle it + else if ( s != NULL && *++s == '/') + retval = FAIL; else p = NULL; }
FYI:
the different between tar and zip:
tarfile::bar.txt~/zipfile:/home/shane/bar.zip::bar.txttarfile::bar.txt
Shoot. That indicates that the tarplugin is also broken with my patch.
um.. actually tar.vim is working still somehow for now, but zip.vim is not.
// ~/zipfile: that ~/ looks odd to me as first expression.
I think the issue could be fixed by passing expand("<amatch>") to fnamemodify(":."). As a suggestion, here is a patch:
diff --git a/runtime/plugin/zipPlugin.vim b/runtime/plugin/zipPlugin.vim index b9e334fb9..ce9ba0db9 100644 --- a/runtime/plugin/zipPlugin.vim +++ b/runtime/plugin/zipPlugin.vim @@ -34,19 +34,19 @@ endif " Public Interface: {{{1 augroup zip au! - au BufReadCmd zipfile:* call zip#Read(expand("<amatch>"), 1) - au FileReadCmd zipfile:* call zip#Read(expand("<amatch>"), 0) - au BufWriteCmd zipfile:* call zip#Write(expand("<amatch>")) - au FileWriteCmd zipfile:* call zip#Write(expand("<amatch>")) + au BufReadCmd zipfile:* call expand('<amatch>')->fnamemodify(':.')->zip#Read(1) + au FileReadCmd zipfile:* call expand('<amatch>')->fnamemodify(':.')->zip#Read(0) + au BufWriteCmd zipfile:* call expand('<amatch>')->fnamemodify(':.')->zip#Write() + au FileWriteCmd zipfile:* call expand('<amatch>')->fnamemodify(':.')->zip#Write() - if has("unix") - au BufReadCmd zipfile:*/* call zip#Read(expand("<amatch>"), 1) - au FileReadCmd zipfile:*/* call zip#Read(expand("<amatch>"), 0) - au BufWriteCmd zipfile:*/* call zip#Write(expand("<amatch>")) - au FileWriteCmd zipfile:*/* call zip#Write(expand("<amatch>")) + if has('unix') + au BufReadCmd zipfile:*/* call expand('<amatch>')->fnamemodify(':.')->zip#Read(1) + au FileReadCmd zipfile:*/* call expand('<amatch>')->fnamemodify(':.')->zip#Read(0) + au BufWriteCmd zipfile:*/* call expand('<amatch>')->fnamemodify(':.')->zip#Write() + au FileWriteCmd zipfile:*/* call expand('<amatch>')->fnamemodify(':.')->zip#Write() endif - exe "au BufReadCmd ".g:zipPlugin_ext.' call zip#Browse(expand("<amatch>"))' + exe 'au BufReadCmd ' .. g:zipPlugin_ext .. ' call expand("<amatch>")->fnamemodify(":.")->zip#Browse()' augroup END " ---------------------------------------------------------------------
Considering Vim already deals with some-protocol:// in absolute path calculation (grep with path_with_url), I think replacing zipfile: by zipfile:// (both autoload and plugin) fixes the problem. Can anyone test this?
Yes, I did a sed -i 's=zipfile:=zipfile://=g' to all runtime files and it worked.
Okay, thanks. Unfortunate that fixing a bug broke an existing plugin, but using zipfile:// looks better solution than proposed in this thread. The zip plugin implementation is valid under the idea of URI, where //authority is optional, but Vim cannot distinguish this resource identifier from actual (relative) file paths. Based on the implementation of path_with_url (and vim_isAbsName), using :// in plugins looks a good convention to me.
@cecamp @chrisbra @lacygoill Do you have any thoughts?
I agree, that using zipfile:// make sense.
When I use zipfile:// as the leader for various zipped file containers, the internally contained files often show up as zipfile:/// . So, would prepending zipfile:/ be sufficient to prevent problems with the patch? (that shows up as zipfile://).
No, that would not work on Windows because absolute paths start with a drive letter.
OK, please try v32c of http://www.drchip.org/astronaut/vim/index#ZIP.
btw I knew that browsers use the https:///... style, I just didn't want zip.vim interfering with something -- like browsers.
Looks like markdown is biting me today. That link should be zip.vim. I hope.
I think the comment in history section is inconsistent with the changes.
Fixed in the latest update of the runtime files.
Closed #8974.