mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Rework logic
This commit is contained in:
parent
b766ae10e9
commit
1dc731c9f7
@ -283,7 +283,8 @@ class FileHelpers:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def unzip_file(zip_path, single_item=False):
|
||||
def unzip_file(zip_path, server_update=False):
|
||||
ignored_names = ["server.properties", "permissions.json", "allowlist.json"]
|
||||
# Get directory without zipfile name
|
||||
new_dir = pathlib.Path(zip_path).parents[0]
|
||||
# make sure we're able to access the zip file
|
||||
@ -296,14 +297,12 @@ class FileHelpers:
|
||||
with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
||||
# we'll extract this to the temp dir using zipfile module
|
||||
zip_ref.extractall(temp_dir)
|
||||
|
||||
# we'll check if the single item parameter was passed
|
||||
# if it was the developer only wants one file back
|
||||
# probably for a server executable update.
|
||||
if not single_item:
|
||||
# we'll iterate through the top level directory moving everything
|
||||
# out of the temp directory and into it's final home.
|
||||
for item in os.listdir(temp_dir):
|
||||
# if the file is one of our ignored names we'll skip it
|
||||
if item in ignored_names and server_update:
|
||||
continue
|
||||
# we handle files and dirs differently or we'll crash out.
|
||||
if os.path.isdir(os.path.join(temp_dir, item)):
|
||||
try:
|
||||
@ -314,6 +313,7 @@ class FileHelpers:
|
||||
except Exception as ex:
|
||||
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
|
||||
else:
|
||||
|
||||
try:
|
||||
FileHelpers.move_file(
|
||||
os.path.join(temp_dir, item),
|
||||
@ -321,18 +321,6 @@ class FileHelpers:
|
||||
)
|
||||
except Exception as ex:
|
||||
logger.error(f"ERROR IN ZIP IMPORT: {ex}")
|
||||
else:
|
||||
# if there is a single item the correct file name should be passed
|
||||
# we'll just try to move that one file based on the name provided
|
||||
# then we'll move along.
|
||||
try:
|
||||
FileHelpers.move_file(
|
||||
os.path.join(temp_dir, single_item),
|
||||
os.path.join(new_dir, single_item),
|
||||
)
|
||||
except FileNotFoundError:
|
||||
logger.error("Could not unpack single file in bedrock update.")
|
||||
return "false"
|
||||
except Exception as ex:
|
||||
Console.error(ex)
|
||||
else:
|
||||
|
@ -1320,10 +1320,7 @@ class ServerInstance:
|
||||
unzip_path = os.path.join(self.settings["path"], "bedrock_server.zip")
|
||||
unzip_path = self.helper.wtol_path(unzip_path)
|
||||
# unzips archive that was downloaded.
|
||||
if self.helper.is_os_windows():
|
||||
FileHelpers.unzip_file(unzip_path, "bedrock_server.exe")
|
||||
else:
|
||||
FileHelpers.unzip_file(unzip_path, "bedrock_server")
|
||||
FileHelpers.unzip_file(unzip_path, server_update=True)
|
||||
# adjusts permissions for execution if os is not windows
|
||||
if not self.helper.is_os_windows():
|
||||
os.chmod(
|
||||
@ -1337,6 +1334,7 @@ class ServerInstance:
|
||||
logger.critical(
|
||||
f"Failed to download bedrock executable for update \n{e}"
|
||||
)
|
||||
downloaded = False
|
||||
|
||||
if downloaded:
|
||||
logger.info("Executable updated successfully. Starting Server")
|
||||
|
Loading…
Reference in New Issue
Block a user