[MERGE] Bugfix #68124: Allow import plugins from zip archives

Alexander Belchenko bialix at ukr.net
Tue Jan 2 14:22:57 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aaron Bentley пишет:
> Alexander Belchenko wrote:
>> This patch solve problem with bzr.exe and built-in plugin launchpad
>> (bug #68124) and simultaneously provide ability to load plugins
>> from any zip archive (of course if this zip will be listed
>> in BZR_PLUGIN_PATH environment variable).
> 
> I notice that this uses slash and backslash.  And apparently directories
> are distinguished from files by a trailing separator.  So does this mean
> that zips created on *nix have '/' and zips created on win32 have '\'?

No. Inside zip always used '/'.
Trailing separator could occurs only if someone create directory inside zip
explicitly (or it's empty directory). Actually to store file 'dir/file.txt'
inside zip you don't need to create separately directory entry 'dir'
and file entry 'dir/file.txt' -- one file entry is enough.
So my check

if not name or name.endswith('/'):
    continue

is just to explicitly check and speed up. It's not important here.

> How much do we have to worry about cross-platform compatibility here?

I think we don't need to worry.
Inside zips all names have forward slashes as separator.
To provide compatibility between required form (a '/')
and possible form on win32 (a '\') I convert back slashes
explicitly:

        if ziobj.prefix:
            prefix = ziobj.prefix.replace('\\','/')
            ix = len(prefix)
            namelist = [name[ix:]
                        for name in namelist
                        if name.startswith(prefix)]

Otherwise sorting of namelist did not working on win32.

ziobj.prefix here it's a part inside zip.
It's important for fixing bug #68124, because in typical case
with bzr.exe we have default location as:

C:\Program Files\Bazaar\lib\library.zip\bzrlib\plugins\

So ziobj.prefix here is 'bzrlib\plugins\'.


In the tests there is workaround because of bug I discover
in zipimport library: if filepath to zip archive
does not contains a '/' it's impossible to correctly
import modules from zip archives. So I need to explicitly
specify filepath to zip in current directory:

        self.check_plugin_load('./test.zip', 'ziplug')

Although for win32 it's looks superfluous.

Alexander

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFmmrBzYr338mxwCURApLLAJ92BIB0mDSz5tm9fZdIYAB9uZO+zgCgjmeT
kSlWdARw0U07ikkbQvL2Lwo=
=Lj7E
-----END PGP SIGNATURE-----




More information about the bazaar mailing list