From d0d37c40e770932d88b0a50db344d244fd4ebf19 Mon Sep 17 00:00:00 2001 From: derrod Date: Wed, 1 Dec 2021 20:45:17 +0100 Subject: [PATCH] [models/downloader] Add task flag to make file executable --- legendary/downloader/mp/manager.py | 3 +++ legendary/downloader/mp/workers.py | 15 +++++++++++++++ legendary/models/downloading.py | 1 + 3 files changed, 19 insertions(+) diff --git a/legendary/downloader/mp/manager.py b/legendary/downloader/mp/manager.py index 0bc501a..4cb5453 100644 --- a/legendary/downloader/mp/manager.py +++ b/legendary/downloader/mp/manager.py @@ -352,6 +352,9 @@ class DLManager(Process): self.tasks.extend(chunk_tasks) self.tasks.append(FileTask(current_file.filename, flags=TaskFlags.CLOSE_FILE)) + if current_file.executable: + self.tasks.append(FileTask(current_file.filename, flags=TaskFlags.MAKE_EXECUTABLE)) + # check if runtime cache size has changed if current_cache_size > last_cache_size: self.log.debug(f' * New maximum cache size: {current_cache_size / 1024 / 1024:.02f} MiB') diff --git a/legendary/downloader/mp/workers.py b/legendary/downloader/mp/workers.py index 96be350..0b647c9 100644 --- a/legendary/downloader/mp/workers.py +++ b/legendary/downloader/mp/workers.py @@ -230,6 +230,21 @@ class FileWorker(Process): self.o_q.put(WriterTaskResult(success=True, **j.__dict__)) continue + elif j.flags & TaskFlags.MAKE_EXECUTABLE: + if current_file: + logger.warning('Trying to chmod file without closing first!') + current_file.close() + current_file = None + + try: + st = os.stat(full_path) + os.chmod(full_path, st.st_mode | 0o111) + except OSError as e: + if not j.flags & TaskFlags.SILENT: + logger.error(f'chmod\'ing file failed: {e!r}') + + self.o_q.put(WriterTaskResult(success=True, **j.__dict__)) + continue try: if j.shared_memory: diff --git a/legendary/models/downloading.py b/legendary/models/downloading.py index 83e04ba..a0538e4 100644 --- a/legendary/models/downloading.py +++ b/legendary/models/downloading.py @@ -62,6 +62,7 @@ class TaskFlags(Flag): CREATE_EMPTY_FILE = auto() RENAME_FILE = auto() RELEASE_MEMORY = auto() + MAKE_EXECUTABLE = auto() SILENT = auto()