[models/downloader] Add task flag to make file executable

This commit is contained in:
derrod 2021-12-01 20:45:17 +01:00
parent c9f9d38f1b
commit d0d37c40e7
3 changed files with 19 additions and 0 deletions

View file

@ -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')

View file

@ -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:

View file

@ -62,6 +62,7 @@ class TaskFlags(Flag):
CREATE_EMPTY_FILE = auto()
RENAME_FILE = auto()
RELEASE_MEMORY = auto()
MAKE_EXECUTABLE = auto()
SILENT = auto()