def testUnzipFile(self): self.AssertExpectedDirFiles(self.tmp_dir) unzip_path = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) dependency_manager_util.UnzipArchive(self.archive_path, unzip_path) self.AssertExpectedDirFiles(unzip_path) self.AssertExpectedDirFiles(self.tmp_dir) dependency_manager_util.RemoveDir(unzip_path)
def testUnzipFileContainingLongPath(self): try: dir_path = self.tmp_dir if sys.platform.startswith('win'): dir_path = u'\\\\?\\' + dir_path archive_suffix = '' # 260 is the Windows API path length limit. while len(archive_suffix) < 260: archive_suffix = os.path.join(archive_suffix, 'really') contents_dir_path = os.path.join(dir_path, archive_suffix) os.makedirs(contents_dir_path) filename = os.path.join(contents_dir_path, 'longpath.txt') open(filename, 'a').close() base_path = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) archive_path = shutil.make_archive(base_path, 'zip', dir_path) self.assertTrue(os.path.exists(archive_path)) self.assertTrue(zipfile.is_zipfile(archive_path)) except: if os.path.isfile(archive_path): os.remove(archive_path) raise unzip_path = os.path.join(tempfile.gettempdir(), str(uuid.uuid4())) dependency_manager_util.UnzipArchive(archive_path, unzip_path) dependency_manager_util.RemoveDir(unzip_path)
def GetUnzippedPath(self): if self.ShouldUnzipArchive(): # TODO(aiolos): Replace UnzipFile with zipfile.extractall once python # version 2.7.4 or later can safely be assumed. dependency_manager_util.UnzipArchive(self._archive_file, self._unzip_path) if self.ShouldUnzipArchive(): raise exceptions.ArchiveError( "Expected path '%s' was not extracted from archive '%s'." % (self._dependency_path, self._archive_file)) return self._dependency_path
def GetUnzippedPath(self): if self.ShouldUnzipArchive(): # Remove stale unzip results if self._stale_unzip_path_glob: for path in glob.glob(self._stale_unzip_path_glob): shutil.rmtree(path, ignore_errors=True) # TODO(aiolos): Replace UnzipFile with zipfile.extractall once python # version 2.7.4 or later can safely be assumed. dependency_manager_util.UnzipArchive(self._archive_file, self._unzip_path) if self.ShouldUnzipArchive(): raise exceptions.ArchiveError( "Expected path '%s' was not extracted from archive '%s'." % (self._dependency_path, self._archive_file)) return self._dependency_path