]> us-delaporte.pagekite.me Git - dotfiles.git/commitdiff
Update to not leave empty backup dirs
authorEdward Delaporte <edward@delaporte.us>
Fri, 18 Oct 2024 03:22:05 +0000 (22:22 -0500)
committerEdward Delaporte <edward@delaporte.us>
Fri, 18 Oct 2024 03:22:05 +0000 (22:22 -0500)
invoke/minetest/tasks.py

index a926cda527b73b70854912341051748988b97ddd..e412a6796532a8429e71669c58a38697710332c1 100644 (file)
@@ -108,8 +108,13 @@ def bkmod(c, name=None):
 @task
 def rmod(c, name):
     '''Restore a backed up set of mods.'''
 @task
 def rmod(c, name):
     '''Restore a backed up set of mods.'''
-    bk = datetime.datetime.now().strftime("%Y%h%d%H%M")
-    c.run(f"mv {mod_dir} {root}/mods_{bk}")
+    if len(os.listdir(f"{mod_dir}")) != 0:
+        bk = datetime.datetime.now().strftime("%Y%h%d%H%M")
+        print(f"Backed up non-emtpy mod dir to mods_{bk}.")
+        c.run(f"mv {mod_dir} {root}/mods_{bk}")
+    else:
+        print("Removing empty mod dir.")
+        c.run(f"rmdir {mod_dir}")
     c.run(f"mv {root}/mods_{name} {mod_dir}")
     c.run(f"ls {root}")
 
     c.run(f"mv {root}/mods_{name} {mod_dir}")
     c.run(f"ls {root}")