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
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): def unzip_file(file_name):
""" """
Takes str file_name Takes (str) file_name
Returns dict with boolean status and str msg Returns dict with (boolean) status and (list of str) msg
""" """
from subprocess import run from subprocess import run
server_info = get_server_info() server_info = get_server_info()
unzip_proc = run( 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 f"{server_info['image_dir']}/{file_name}"], capture_output=True
) )
if unzip_proc.returncode != 0: if unzip_proc.returncode != 0:
logging.warning(f"Unzipping failed: {unzip_proc}") stderr = unzip_proc.stderr.decode("utf-8")
return {"status": False, "msg": str(unzip_proc)} 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): def download_file_to_iso(scsi_id, url):

View File

@@ -640,7 +640,12 @@ def unzip():
process = unzip_file(image) process = unzip_file(image)
if process["status"]: 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")) return redirect(url_for("index"))
else: else:
flash("Failed to unzip " + image, "error") flash("Failed to unzip " + image, "error")