From 580de8836629ea8ec0a7b11f9542ca957ced4c50 Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Wed, 26 Mar 2025 21:32:23 +0400 Subject: [PATCH] Set the new session filename *before* copying Fixes a potential bug whereby if the copy fails for some reason, the 'cleanup' command would remove the original session file --- .../modules/telethon_extractor/telethon_extractor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/auto_archiver/modules/telethon_extractor/telethon_extractor.py b/src/auto_archiver/modules/telethon_extractor/telethon_extractor.py index 018b62b..434d97c 100644 --- a/src/auto_archiver/modules/telethon_extractor/telethon_extractor.py +++ b/src/auto_archiver/modules/telethon_extractor/telethon_extractor.py @@ -35,10 +35,10 @@ class TelethonExtractor(Extractor): self.session_file = self.session_file.removesuffix(".session") # make a copy of the session that is used exclusively with this archiver instance - new_session_file = os.path.join("secrets/", f"telethon-{time.strftime('%Y-%m-%d')}{random_str(8)}") - logger.debug(f"Making a copy of the session file {self.session_file}.session to {new_session_file}.session") - shutil.copy(f"{self.session_file}.session", f"{new_session_file}.session") - self.session_file = new_session_file + old_session_file = f"{self.session_file}.session" + self.session_file = os.path.join("secrets/", f"telethon-{time.strftime('%Y-%m-%d')}{random_str(8)}") + logger.debug(f"Making a copy of the session file {old_session_file} to {self.session_file}.session") + shutil.copy(old_session_file, f"{self.session_file}.session") # initiate the client self.client = TelegramClient(self.session_file, self.api_id, self.api_hash)