Skip to content

Commit ae757c1

Browse files
committed
Modify copy of unpacked bundle
This resolves write issues when the provided and unpacked bundle is readonly.
1 parent 5a214e7 commit ae757c1

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

codeql_bundle/helpers/bundle.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ class BundleException(Exception):
2323

2424
class Bundle:
2525
def __init__(self, bundle_path: Path) -> None:
26-
self.tmp_dir = None
26+
self.tmp_dir = TemporaryDirectory()
2727
if bundle_path.is_dir():
28-
self.bundle_path = bundle_path
28+
self.bundle_path = Path(self.tmp_dir.name) / bundle_path.name
29+
shutil.copytree(
30+
bundle_path,
31+
self.bundle_path,
32+
)
2933
elif bundle_path.is_file() and bundle_path.name.endswith(".tar.gz"):
30-
self.tmp_dir = TemporaryDirectory()
3134
logging.info(
3235
f"Unpacking provided bundle {bundle_path} to {self.tmp_dir.name}."
3336
)
@@ -40,6 +43,8 @@ def __init__(self, bundle_path: Path) -> None:
4043
self.codeql = CodeQL(self.bundle_path / "codeql")
4144
try:
4245
logging.info(f"Validating the CodeQL CLI version part of the bundle.")
46+
unpacked_location = self.codeql.unpacked_location()
47+
logging.debug(f"Found CodeQL CLI in {str(unpacked_location)}.")
4348
version = self.codeql.version()
4449
logging.info(f"Found CodeQL CLI version {version}.")
4550
except CodeQLException:

codeql_bundle/helpers/codeql.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def version(self) -> Version:
8383
else:
8484
raise CodeQLException(f"Failed to run {cp.args} command!")
8585

86+
def unpacked_location(self) -> Path:
87+
cp = self._exec("version", "--format=json")
88+
if cp.returncode == 0:
89+
version_info = json.loads(cp.stdout)
90+
return Path(version_info["unpackedLocation"])
91+
else:
92+
raise CodeQLException(f"Failed to run {cp.args} command!")
93+
8694
def supports_qlx(self) -> bool:
8795
return self.version() >= Version("2.11.4")
8896

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "codeql-bundle"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "Tool to create custom CodeQL bundles"
55
authors = ["Remco Vermeulen <rvermeulen@users.noreply.github.com>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)