Fix incorrect path to zip file to unzip; improve error handling

This commit is contained in:
Daniel Markstedt 2021-10-24 11:07:26 -07:00
parent c706fedfd3
commit dd6d289395
2 changed files with 7 additions and 5 deletions

View File

@ -146,13 +146,13 @@ def unzip_file(file_name):
unzip_proc = run(
["unzip", "-d", server_info["image_dir"], "-o", "-j", \
server_info["image_dir"] + file_name], capture_output=True
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": unzip_proc}
return {"status": False, "msg": str(unzip_proc)}
return {"status": True, "msg": f"{file_name} unzipped"}
return {"status": True, "msg": f"Unzipped {file_name} to {server_info['image_dir']}"}
def download_file_to_iso(scsi_id, url):

View File

@ -638,11 +638,13 @@ def delete():
def unzip():
image = request.form.get("image")
if unzip_file(image):
flash("Unzipped file " + image)
process = unzip_file(image)
if process["status"]:
flash(process["msg"])
return redirect(url_for("index"))
else:
flash("Failed to unzip " + image, "error")
flash(process["msg"], "error")
return redirect(url_for("index"))