mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-21 08:29:59 +00:00
More verbose unzipping; don't overwrite existing files (#378)
This commit is contained in:
parent
cc1783c1cd
commit
87640a7c2c
@ -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):
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user