Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error with execution right on linux afer extraction from zip #208

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
long_description_content_type="text/markdown",
packages=setuptools.find_packages(exclude=['tests']),
include_package_data=True,
version='3.4.2',
version='3.4.3',
description=('Library provides the way to automatically manage drivers for different browsers'),
author='Sergey Pirogov',
author_email='automationremarks@gmail.com',
Expand Down
23 changes: 21 additions & 2 deletions webdriver_manager/archive.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import os
import tarfile
import zipfile
import typing


class LinuxZipFileWithPermissions(zipfile.ZipFile):
"""Class for extract files in linux with right permissions"""
def extract(self, member, path=None, pwd=None):
if not isinstance(member, zipfile.ZipInfo):
member = self.getinfo(member)

if path is None:
path = os.getcwd()

ret_val = self._extract_member(member, path, pwd) # noqa
attr = member.external_attr >> 16
os.chmod(ret_val, attr)
return ret_val


class Archive(object):

def __init__(self, path: str):
def __init__(self, path: str, os_type: typing.Optional[str] = None):
self.file_path = path
self.os_type: typing.Optional[str] = os_type

def unpack(self, directory):
if self.file_path.endswith(".zip"):
Expand All @@ -14,7 +32,8 @@ def unpack(self, directory):
return self.__extract_tar_file(directory)

def __extract_zip(self, to_directory):
archive = zipfile.ZipFile(self.file_path)
zip_class = LinuxZipFileWithPermissions if self.os_type == "linux" else zipfile.ZipFile
archive = zip_class(self.file_path)
try:
archive.extractall(to_directory)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion webdriver_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_file(file: File, directory: str):
archive_path = f"{directory}{os.sep}{file.filename}"
with open(archive_path, "wb") as code:
code.write(file.content)
return Archive(archive_path)
return Archive(archive_path, os_type=os_name())


class OSType(object):
Expand Down