Add backward compatibility for new way of extracting tar files

This commit is contained in:
Théophile Diot 2024-03-15 14:05:21 +00:00
parent ece8ad7f16
commit 07e438920f
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
4 changed files with 24 additions and 6 deletions

View file

@ -137,10 +137,16 @@ try:
zf.extractall(path=temp_dir)
elif file_type == "application/gzip":
with tar_open(fileobj=BytesIO(content), mode="r:gz") as tar:
tar.extractall(path=temp_dir, filter="data")
try:
tar.extractall(path=temp_dir, filter="data")
except TypeError:
tar.extractall(path=temp_dir)
elif file_type == "application/x-tar":
with tar_open(fileobj=BytesIO(content), mode="r") as tar:
tar.extractall(path=temp_dir, filter="data")
try:
tar.extractall(path=temp_dir, filter="data")
except TypeError:
tar.extractall(path=temp_dir)
else:
LOGGER.error(f"Unknown file type for {plugin_url}, either zip or tar are supported, skipping...")
continue

View file

@ -75,7 +75,10 @@ class Job:
rmtree(extract_path, ignore_errors=True)
extract_path.mkdir(parents=True, exist_ok=True)
with tar_open(fileobj=BytesIO(job_cache_file["data"]), mode="r:gz") as tar:
tar.extractall(extract_path, filter="fully_trusted")
try:
tar.extractall(extract_path, filter="fully_trusted")
except TypeError:
tar.extractall(extract_path)
continue
elif job_cache_file["job_name"] != job_name:
continue

View file

@ -134,7 +134,10 @@ def generate_external_plugins(plugins: List[Dict[str, Any]], *, original_path: U
tmp_path.parent.mkdir(parents=True, exist_ok=True)
tmp_path.write_bytes(plugin["data"])
with tar_open(str(tmp_path), "r:gz") as tar:
tar.extractall(original_path, filter="fully_trusted")
try:
tar.extractall(original_path, filter="fully_trusted")
except TypeError:
tar.extractall(original_path)
tmp_path.unlink()
for job_file in glob(join(str(tmp_path.parent), "jobs", "*")):

View file

@ -1183,7 +1183,10 @@ def plugins():
tar_file.getmember("plugin.json")
except KeyError:
is_dir = True
tar_file.extractall(str(temp_folder_path), filter="data")
try:
tar_file.extractall(str(temp_folder_path), filter="data")
except TypeError:
tar_file.extractall(str(temp_folder_path))
except ReadError:
errors += 1
error = 1
@ -1387,7 +1390,10 @@ def upload_plugin():
if file.endswith("plugin.json"):
plugins.append(basename(dirname(file)))
if len(plugins) > 1:
tar_file.extractall(str(tmp_ui_path) + "/", filter="data")
try:
tar_file.extractall(str(tmp_ui_path) + "/", filter="data")
except TypeError:
tar_file.extractall(str(tmp_ui_path) + "/")
folder_name = uploaded_file.filename.replace(".tar.gz", "").replace(".tar.xz", "")
if len(plugins) <= 1: