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

Add alternate unzip implementation #1692

Merged
merged 1 commit into from
Sep 16, 2023
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
29 changes: 18 additions & 11 deletions buildozer/buildops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tarfile
from threading import Thread
from urllib.request import Request, urlopen
from zipfile import ZipFile

from buildozer.exceptions import BuildozerCommandException
from buildozer.logger import Logger
Expand Down Expand Up @@ -127,17 +128,23 @@ def file_extract(archive, env, cwd="."):

if path.suffix == ".zip":
LOGGER.debug("Extracting {0} to {1}".format(archive, cwd))
assert platform != "win32", "unzip unavailable on Windows"
# This should use python's zipfile library, with suitable handling of
# Unix permissions.
# However, this lead to unexpected config script issues, so sticking to
# unzip for now.
return_code = cmd(
["unzip", "-q", join(cwd, archive)], cwd=cwd, env=env
).return_code
if return_code != 0:
raise BuildozerCommandException(
"Unzip gave bad return code: {}".format(return_code))
if platform == "win32":
# This won't work on Unix/OSX, because Android NDK (for example)
# relies on non-standard handling of file permissions and symbolic
# links that Python's zipfile doesn't support.
# Windows doesn't support them either.
with ZipFile(path, "r") as compressed_file:
compressed_file.extractall(cwd)
return
else:
# This won't work on Windows, because there is no unzip command
# there
return_code = cmd(
["unzip", "-q", join(cwd, archive)], cwd=cwd, env=env
).return_code
if return_code != 0:
raise BuildozerCommandException(
"Unzip gave bad return code: {}".format(return_code))
return

if path.suffix == ".bin":
Expand Down
10 changes: 7 additions & 3 deletions tests/test_buildops.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ def test_extract_file(self):
m_logger.reset_mock()

nonexistent_path = Path(base_dir) / "nonexistent.zip"
with self.assertRaises(BuildozerCommandException):
try:
buildops.file_extract(nonexistent_path, environ)
m_logger.debug.assert_called()
m_logger.error.assert_called()
self.fail("No exception raised")
except FileNotFoundError:
pass # This is raised by zipfile on Windows.
except BuildozerCommandException:
pass # This is raised by cmd when not on Windows.

m_logger.reset_mock()

# Create a zip file and unzip it.
Expand Down
Loading