Skip to content

Commit b72a0dd

Browse files
author
gsherman
committedJan 15, 2008
Potential fix for directory unzip problems
git-svn-id: http://svn.osgeo.org/qgis/trunk@7969 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent abe00ff commit b72a0dd

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed
 

‎python/plugins/plugin_installer/qgis_plugins.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def extract(self, file, dir):
4040
zf = zipfile.ZipFile(file)
4141

4242
# create directory structure to house files
43+
print "Creating plugin structure"
4344
self._createstructure(file, dir)
4445

4546
num_files = len(zf.namelist())
@@ -69,10 +70,16 @@ def _createstructure(self, file, dir):
6970

7071
def _makedirs(self, directories, basedir):
7172
""" Create any directories that don't currently exist """
73+
print "Creating directories contained in the zip file: %s" % directories
7274
for dir in directories:
7375
curdir = os.path.join(basedir, dir)
76+
# normalize the path
77+
curdir = os.path.normpath(curdir)
78+
print "Checking to see if we should create %s" % curdir
7479
if not os.path.exists(curdir):
75-
os.mkdir(curdir)
80+
# use makedirs to create parent directories as well
81+
print "Creating %s" % curdir
82+
os.makedirs(curdir)
7683

7784
def _listdirs(self, file):
7885
""" Grabs all the directories in the zip structure
@@ -82,9 +89,22 @@ def _listdirs(self, file):
8289

8390
dirs = []
8491

85-
for name in zf.namelist():
86-
if name.endswith('/'):
87-
dirs.append(name)
92+
for file in zf.filelist:
93+
if file.external_attr >> 28 == 4:
94+
print "Adding %s to the list of directories to create" % file.filename
95+
dirs.append(file.filename)
96+
97+
#for name in zf.namelist():
98+
# if name.endswith('/'):
99+
# dirs.append(name)
100+
101+
## Check for subdirectories by assuming a file with length 0
102+
## is a directory (this isn't necessarily true but it allows
103+
## plugins with subdirectories to be installed)
104+
#for file in zf.filelist:
105+
# if file.file_size == 0:
106+
# dirs.append(file.file_name)
107+
88108

89109
if len(dirs) == 0:
90110
# this means there is no top level directory in the
@@ -115,6 +135,8 @@ def retrieve_list(repos):
115135
return plugins
116136

117137
def install_plugin(plugin, plugindir, repos):
138+
# normalize the path to the users plugin directory
139+
plugindir = os.path.normpath(plugindir)
118140
plugin_list = retrieve_list(repos)
119141
target = [x for x in plugin_list if x["name"] == plugin]
120142
if target:
@@ -138,7 +160,7 @@ def install_plugin(plugin, plugindir, repos):
138160

139161
print "Extracting to plugin directory (%s)" % plugindir
140162
try:
141-
un = unzip()
163+
un = unzip()
142164
un.extract(outfile, plugindir)
143165
except:
144166
return (False, "Failed to unzip file to %s ... check permissions" % plugindir)

0 commit comments

Comments
 (0)
Please sign in to comment.