delete _HOME_ if not used after game is done master
authorNiki Roo <niki@nikiroo.be>
Tue, 30 Dec 2025 22:08:17 +0000 (23:08 +0100)
committerNiki Roo <niki@nikiroo.be>
Tue, 30 Dec 2025 22:08:17 +0000 (23:08 +0100)
gamiki/support/commands.py

index d0454e9b942124e27d386f4e5c94fc32c9f5c586..b6f872e7d6d01449c0506c31dd2640b8360a168d 100644 (file)
@@ -1,6 +1,6 @@
 from subprocess import run
 from shutil     import which
 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 = { }
 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()
     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.")
+