From: Niki Roo Date: Tue, 30 Dec 2025 22:08:17 +0000 (+0100) Subject: delete _HOME_ if not used after game is done X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;ds=sidebyside;p=gamiki.git delete _HOME_ if not used after game is done --- 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.") +