diff --git a/app/classes/shared/file_helpers.py b/app/classes/shared/file_helpers.py index 04ec3305..28edbef7 100644 --- a/app/classes/shared/file_helpers.py +++ b/app/classes/shared/file_helpers.py @@ -64,6 +64,11 @@ class FileHelpers: FileHelpers.copy_dir(src_path, dest_path) FileHelpers.del_dirs(src_path) + @staticmethod + def move_dir_exist(src_path, dest_path): + FileHelpers.copy_dir(src_path, dest_path, True) + FileHelpers.del_dirs(src_path) + @staticmethod def move_file(src_path, dest_path): FileHelpers.copy_file(src_path, dest_path) @@ -290,7 +295,7 @@ class FileHelpers: for item in os.listdir(full_root_path): if os.path.isdir(os.path.join(full_root_path, item)): try: - FileHelpers.move_dir( + FileHelpers.move_dir_exist( os.path.join(full_root_path, item), os.path.join(new_dir, item), ) diff --git a/app/classes/shared/server.py b/app/classes/shared/server.py index 0b2c5b96..cee0a8e9 100644 --- a/app/classes/shared/server.py +++ b/app/classes/shared/server.py @@ -9,6 +9,7 @@ import threading import logging.config import subprocess import html +import urllib.request # TZLocal is set as a hidden import on win pipeline from tzlocal import get_localzone @@ -1100,13 +1101,32 @@ class ServerInstance: self.settings["executable"], ) - # copies to backup dir - FileHelpers.copy_file(current_executable, backup_executable) + try: + # copies to backup dir + FileHelpers.copy_file(current_executable, backup_executable) + except FileNotFoundError: + logger.error("Could not create backup of jarfile. File not found.") - # boolean returns true for false for success - downloaded = Helpers.download_file( - self.settings["executable_update_url"], current_executable - ) + if HelperServers.get_server_type_by_id(self.server_id) != "minecraft-bedrock": + # boolean returns true for false for success + downloaded = Helpers.download_file( + self.settings["executable_update_url"], current_executable + ) + else: + print("in download") + # downloads zip from remote url + urllib.request.urlretrieve( + self.settings["executable_update_url"], + os.path.join(self.settings["path"], "bedrock_server.zip"), + ) + unzip_path = os.path.join(self.settings["path"], "bedrock_server.zip") + unzip_path = self.helper.wtol_path(unzip_path) + # unzips archive that was downloaded. + FileHelpers.unzip_file(unzip_path) + # adjusts permissions for execution if os is not windows + if not self.helper.is_os_windows(): + os.chmod(os.path.join(self.settings["path"], "bedrock_server"), 0o0775) + downloaded = True while self.stats_helper.get_server_stats()["updating"]: if downloaded and not self.is_backingup: