From 2ffb11d45805b8422ed25cc4a9ad6c5d6cba07d3 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Tue, 30 Dec 2025 23:08:17 +0100 Subject: [PATCH] delete _HOME_ if not used after game is done --- gamiki/support/commands.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gamiki/support/commands.py b/gamiki/support/commands.py index d0454e9..b6f872e 100644 --- a/gamiki/support/commands.py +++ b/gamiki/support/commands.py @@ -1,6 +1,6 @@ from subprocess import run from shutil import which -from os import environ, mkdir +from os import environ, mkdir, scandir from pathlib import PurePath __programs__: dict = { } @@ -103,5 +103,14 @@ def start_sh(dir: PurePath, link: PurePath, opt: str = None) -> int: env["HOME"] = home.as_posix() cmd = startsh.as_posix() - return run(cmd, cwd=dir, env=env).returncode + rc = run(cmd, cwd=dir, env=env).returncode + + # Remove newly-created _HOME_ if it is still empty + if not any(scandir(home.as_posix())): + home.rmdir() + + return rc + + print("Directory is empty.") + -- 2.27.0