Skip to content

Commit

Permalink
executors/local: try cleanup as normal user first
Browse files Browse the repository at this point in the history
If there is no need to use sudo (most of the cases), don't try it. This
avoids polluting logs if sudo is not allowed, or even not installed.
  • Loading branch information
marmarek committed Dec 20, 2024
1 parent da51c55 commit fccd522
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions qubesbuilder/executors/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,29 @@ def copy_out(self, source_path: Path, destination_dir: Path): # type: ignore

def cleanup(self):
try:
subprocess.run(
[
"sudo",
"--non-interactive",
"rm",
"-rf",
"--",
self._temporary_dir,
],
check=True,
)
except subprocess.CalledProcessError as e:
shutil.rmtree(self._temporary_dir)
except PermissionError:
# retry with sudo
try:
# retry without sudo, as local executor for many
# actions doesn't really need it
subprocess.run(
["rm", "-rf", "--", self._temporary_dir],
[
"sudo",
"--non-interactive",
"rm",
"-rf",
"--",
self._temporary_dir,
],
check=True,
)
except subprocess.CalledProcessError as e:
raise ExecutorError(
f"Failed to clean executor temporary directory: {str(e)}"
)
except OSError as e:
raise ExecutorError(
f"Failed to clean executor temporary directory: {str(e)}"
)

def run( # type: ignore
self,
Expand Down

0 comments on commit fccd522

Please sign in to comment.