Skip to content

Commit

Permalink
feat: Support session.cleanup() on Windows (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Luttrell <[email protected]>
  • Loading branch information
roblutt authored Oct 27, 2023
1 parent 02205f3 commit 7eaeecb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/openjd/sessions/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,20 @@ def cleanup(self) -> None:
# removal: 1/ `sudo -u <user> -i rm -rf <sessiondir>`, and then 2/ doing a normal
# recursive removal to delete the stuff that only this user can delete.
if self._user is not None:
files = [str(f) for f in self.working_directory.glob("*")]

if is_posix():
files = [str(f) for f in self.working_directory.glob("*")]
subprocess = LoggingSubprocess(
logger=self._logger,
args=["rm", "-rf"] + files,
user=self._user,
)
# Note: Blocking call until the process has exited
subprocess.run()
recursive_delete_cmd = ["rm", "-rf"]
else:
raise NotImplementedError("Not implemented for non-posix")
recursive_delete_cmd = ["Remove-Item", "-Recurse", "-Force"]

subprocess = LoggingSubprocess(
logger=self._logger,
args=recursive_delete_cmd + files,
user=self._user,
)
# Note: Blocking call until the process has exited
subprocess.run()

self._working_dir.cleanup()
except RuntimeError as exc:
Expand Down

0 comments on commit 7eaeecb

Please sign in to comment.