From e4c3ccbf9729314812707235e3b033c6e6687ed2 Mon Sep 17 00:00:00 2001 From: Specoolazius Date: Sat, 2 Apr 2022 21:39:02 +0200 Subject: [PATCH] fixed permission error --- bot/libs/client.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/bot/libs/client.py b/bot/libs/client.py index 9a89eb3..ab6f69e 100644 --- a/bot/libs/client.py +++ b/bot/libs/client.py @@ -156,25 +156,27 @@ class Client(discord.Bot, ABC): await process_chmod.communicate() return process_chmod.returncode - process = await asyncio.create_subprocess_exec( - program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name), - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE, - ) + if not retry: + await __grant_permission() - stdout, stderr = await process.communicate() - self.logger.info(f'Executed script {file_name} with exit code {process.returncode}') + try: + process = await asyncio.create_subprocess_exec( + program=os.path.join(os.getcwd(), SHELL_SCRIPT_PATH, file_name), + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + ) - if process.returncode == 0: - self.logger.info(f'stdout:\n{stdout.decode()}') + stdout, stderr = await process.communicate() + self.logger.info(f'Executed script {file_name} with exit code {process.returncode}') - # bash returncode 126: permission error - elif process.returncode == 126 and retry: + if process.returncode == 0: + self.logger.info(f'stdout:\n{stdout.decode()}') + else: + self.logger.error(f'stderr:\n{stderr.decode()}') + + return process.returncode + + except PermissionError: # retrying once self.logger.warning(f'Missing permissions for {file_name}') return await self.execute_shell(file_name, retry=False) - - else: - self.logger.error(f'stderr:\n{stderr.decode()}') - - return process.returncode