More verbose unzipping; don't overwrite existing files (#378)

This commit is contained in:
Daniel Markstedt 2021-10-25 18:58:16 -07:00 committed by GitHub
parent cc1783c1cd
commit 87640a7c2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -138,21 +138,24 @@ def delete_file(file_path):
def unzip_file(file_name):
"""
Takes str file_name
Returns dict with boolean status and str msg
Takes (str) file_name
Returns dict with (boolean) status and (list of str) msg
"""
from subprocess import run
server_info = get_server_info()
unzip_proc = run(
["unzip", "-d", server_info["image_dir"], "-o", "-j", \
["unzip", "-d", server_info["image_dir"], "-n", "-j", \
f"{server_info['image_dir']}/{file_name}"], capture_output=True
)
if unzip_proc.returncode != 0:
logging.warning(f"Unzipping failed: {unzip_proc}")
return {"status": False, "msg": str(unzip_proc)}
stderr = unzip_proc.stderr.decode("utf-8")
logging.warning(f"Unzipping failed: {stderr}")
return {"status": False, "msg": stderr}
return {"status": True, "msg": f"Unzipped {file_name} to {server_info['image_dir']}"}
from re import findall
unzipped = findall("inflating:(.+)\n", unzip_proc.stdout.decode("utf-8"))
return {"status": True, "msg": unzipped}
def download_file_to_iso(scsi_id, url):

View File

@ -640,7 +640,12 @@ def unzip():
process = unzip_file(image)
if process["status"]:
flash(process["msg"])
if len(process["msg"]) < 1:
flash("Aborted unzip: File(s) with the same name already exists.", "error")
return redirect(url_for("index"))
flash("Unzipped the following files:")
for m in process["msg"]:
flash(m)
return redirect(url_for("index"))
else:
flash("Failed to unzip " + image, "error")