From 3231f319531781a6fedcdf59044a68579d3ee71c Mon Sep 17 00:00:00 2001 From: samadhi-spice <128258751+samadhi-spice@users.noreply.github.com> Date: Fri, 24 Mar 2023 01:07:04 -0600 Subject: [PATCH 1/2] Add UUID to 'temp' folder The temporary folder gets deleted when orpheus_core_download finishes running. However, the temporary folder will be used by any other instance of orpheusdl that is running and the deletion of this folder will interfere with other instances. In order to prevent interference with other running instances of orpheusdl, here is a proposed change to create the temporary folder with a unique id that will not overlap. --- orpheus/core.py | 6 ++++-- utils/utils.py | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/orpheus/core.py b/orpheus/core.py index bed2ee8..3c14164 100644 --- a/orpheus/core.py +++ b/orpheus/core.py @@ -357,7 +357,9 @@ def update_module_storage(self): # Should be refactored eventually def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_party_modules, separate_download_module, output_path): downloader = Downloader(orpheus_session.settings['global'], orpheus_session.module_controls, oprinter, output_path) - os.makedirs('temp', exist_ok=True) + UUID = os.urandom(5).hex() + share_UUID(UUID) + os.makedirs(f'temp{UUID}', exist_ok=True) for mainmodule, items in media_to_download.items(): for media in items: @@ -404,4 +406,4 @@ def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_par else: raise Exception(f'\tUnknown media type "{mediatype}"') - if os.path.exists('temp'): shutil.rmtree('temp') \ No newline at end of file + if os.path.exists(f'temp{UUID}'): shutil.rmtree(f'temp{UUID}') diff --git a/utils/utils.py b/utils/utils.py index b830dfe..da10b53 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -107,7 +107,7 @@ def silentremove(filename): def read_temporary_setting(settings_location, module, root_setting=None, setting=None, global_mode=False): temporary_settings = pickle.load(open(settings_location, 'rb')) module_settings = temporary_settings['modules'][module] if module in temporary_settings['modules'] else None - + if module_settings: if global_mode: session = module_settings @@ -122,7 +122,7 @@ def read_temporary_setting(settings_location, module, root_setting=None, setting else: return session[root_setting] if root_setting in session else None elif root_setting and not session: - raise Exception('Module does not use temporary settings') + raise Exception('Module does not use temporary settings') else: return session @@ -146,7 +146,11 @@ def set_temporary_setting(settings_location, module, root_setting, setting=None, session[root_setting] = value pickle.dump(temporary_settings, open(settings_location, 'wb')) -create_temp_filename = lambda : f'temp/{os.urandom(16).hex()}' +def share_UUID(UUID_value): + global UUID + UUID = UUID_value + +create_temp_filename = lambda : f'temp{UUID}/{os.urandom(16).hex()}' def save_to_temp(input: bytes): location = create_temp_filename() From 6e70e1c4da4e83100ac361630ff102ed7b5f30b4 Mon Sep 17 00:00:00 2001 From: samadhi-spice <128258751+samadhi-spice@users.noreply.github.com> Date: Sun, 26 Mar 2023 17:23:42 -0600 Subject: [PATCH 2/2] Optimized Concatenation removed unnecessary concatenations of the temp string --- orpheus/core.py | 8 ++++---- utils/utils.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/orpheus/core.py b/orpheus/core.py index 3c14164..34d2213 100644 --- a/orpheus/core.py +++ b/orpheus/core.py @@ -357,9 +357,9 @@ def update_module_storage(self): # Should be refactored eventually def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_party_modules, separate_download_module, output_path): downloader = Downloader(orpheus_session.settings['global'], orpheus_session.module_controls, oprinter, output_path) - UUID = os.urandom(5).hex() - share_UUID(UUID) - os.makedirs(f'temp{UUID}', exist_ok=True) + temp_UUID = f'temp{os.urandom(5).hex()}' + share_temp_UUID(temp_UUID) + os.makedirs(temp_UUID, exist_ok=True) for mainmodule, items in media_to_download.items(): for media in items: @@ -406,4 +406,4 @@ def orpheus_core_download(orpheus_session: Orpheus, media_to_download, third_par else: raise Exception(f'\tUnknown media type "{mediatype}"') - if os.path.exists(f'temp{UUID}'): shutil.rmtree(f'temp{UUID}') + if os.path.exists(temp_UUID): shutil.rmtree(temp_UUID) diff --git a/utils/utils.py b/utils/utils.py index da10b53..be21d17 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -146,11 +146,11 @@ def set_temporary_setting(settings_location, module, root_setting, setting=None, session[root_setting] = value pickle.dump(temporary_settings, open(settings_location, 'wb')) -def share_UUID(UUID_value): - global UUID - UUID = UUID_value +def share_temp_UUID(UUID_value): + global temp_UUID + temp_UUID = UUID_value -create_temp_filename = lambda : f'temp{UUID}/{os.urandom(16).hex()}' +create_temp_filename = lambda : f'{temp_UUID}/{os.urandom(16).hex()}' def save_to_temp(input: bytes): location = create_temp_filename()