Skip to content
Browse files

MB-6452: Use same extractall function as for python 2.4

For python2.6 on Mac, zipfile.extractall() wrongly create parent
directory as file. And it lealds to extractall failure. The ZipUtil
implementation won't have such problems.

Change-Id: I17a7e8dc5a664680ffbce58ba7cd3106c3a527b0
Reviewed-on: http://review.couchbase.org/20880
Reviewed-by: Jens Alfke <jens@couchbase.com>
Tested-by: Farshid Ghods <farshid@couchbase.com>
Reviewed-by: Farshid Ghods <farshid@couchbase.com>
  • Loading branch information...
1 parent 5626f00 commit c71d9aec140c5258689d2d8dd356d689ab587a75 @bcui6611 bcui6611 committed with Farshid Ghods Sep 14, 2012
Showing with 8 additions and 12 deletions.
  1. +8 −12 cbdocloader
View
20 cbdocloader
@@ -147,7 +147,6 @@ class DocLoader:
if os.path.isfile(os.path.join(subdir, item)):
try:
fp = open(os.path.join(subdir, item), 'r')
- print "working with %s" % item
dockey = self.gen_dockey(item)
self.save_doc(dockey, fp)
fp.close()
@@ -166,17 +165,14 @@ class DocLoader:
def unzip_file_and_upload(self):
zfobj = zipfile.ZipFile(self.args[0])
tmpdir = tempfile.gettempdir()
- working_dir = os.path.join(tmpdir, '_working')
- if not os.path.exists(working_dir):
- try:
- os.makedirs(working_dir)
- except:
- print "Unexpected error:", sys.exc_info()[0]
- return
- if sys.version >= "2.6":
- zfobj.extractall(working_dir)
- else:
- ZipUtil(zfobj).extractall(working_dir)
+ working_dir = os.path.join(tmpdir, '_cbdocloader_working')
+ try:
+ shutil.rmtree(working_dir)
+ except:
+ pass
+ os.makedirs(working_dir)
+
+ ZipUtil(zfobj).extractall(working_dir)
self.enumerate_and_save(working_dir)
shutil.rmtree(working_dir)

0 comments on commit c71d9ae

Please sign in to comment.
Something went wrong with that request. Please try again.