From c0865c173562c06967ae20b5a06c5b2655559a96 Mon Sep 17 00:00:00 2001 From: Jose Castillo Date: Thu, 22 Jun 2023 11:40:32 +0100 Subject: [PATCH] [Plugin] Fix exception when calling os.makedirs When calling get_cmd_output_path() to create a directory via the plugin hpssm, sos threw the following exception: Traceback (most recent call last): File "/root/sos/sos/report/__init__.py", line 1224, in setup plug.setup() File "/root/sos/sos/report/plugins/hpssm.py", line 67, in setup logpath = self.get_cmd_output_path() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/sos/sos/report/plugins/__init__.py", line 2168, in get_cmd_output_path os.makedirs(cmd_output_path) File "", line 225, in makedirs FileExistsError: [Errno 17] File exists: '/var/tmp/sos.1gdy83zb/sosreport-localhost-vbwfnpn/sos_commands/hpssm' This was happening because the directory 'hpssm' was already created. With this change we avoid any race where we call os.makedirs() after we have already created the plugin directory. Closes: RHBZ #2216608 Signed-off-by: Jose Castillo --- sos/report/plugins/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sos/report/plugins/__init__.py b/sos/report/plugins/__init__.py index 5209c37a15..e8aedca813 100644 --- a/sos/report/plugins/__init__.py +++ b/sos/report/plugins/__init__.py @@ -2176,7 +2176,7 @@ def get_cmd_output_path(self, name=None, make=True): if name: cmd_output_path = os.path.join(cmd_output_path, name) if make: - os.makedirs(cmd_output_path) + os.makedirs(cmd_output_path, exist_ok=True) return cmd_output_path