Skip to content

Commit

Permalink
Better creation of list of directories of a zip file. Fixes installat…
Browse files Browse the repository at this point in the history
…ion problem with some plugins.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8191 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 6, 2008
1 parent 2a4f4bf commit 2ef17f0
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions python/plugins/plugin_installer/qgis_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,11 @@ def _listdirs(self, file):

dirs = []

for file in zf.filelist:
# It appears that all directories in a zip have a unique
# signature in the external_attr of the ZipInfo object.
# Shifting the external_attr by 28 will result in a value of 4
# for all directories. This is undocumented in the Python zipfile
# module but appears to be a solid way to identify directories
# in a zip file.
if file.external_attr >> 28 == 4:
dirs.append(file.filename)

if len(dirs) == 0:
# this means there is no top level directory in the
# zip file. We'll assume the first entry contains the
# directory and use it, hoping for the best...
entry = zf.namelist()[0]
dir = entry.split('/')[0]
dir += '/'
dirs.append(dir)
for name in zf.namelist():
(path, filename) = os.path.split(name)

if path not in dirs:
dirs.append(path)

dirs.sort()
return dirs
Expand Down

0 comments on commit 2ef17f0

Please sign in to comment.