|

cli: rename — error on both-dirs-exist, end running (review fixes)

Author: Chris Tusa <chris.tusa@leafscale.com>
Date: Jul 15, 2026 16:05
Changeset: aaf24c4e07c5d1e845b8dfe2b2f651aca7abafa2
Branch: default

Changed files:

Diff

diff -r 1963ac59274e -r aaf24c4e07c5 src/cli.reef
--- a/src/cli.reef	Wed Jul 15 14:34:01 2026 -0500
+++ b/src/cli.reef	Wed Jul 15 16:05:07 2026 -0500
@@ -1099,7 +1099,6 @@
         log.write("repoman: error: containers '" + old + "' and '" + new_name + "' both exist; refusing to merge")
         return 1
     end if
-    let was_running: bool = state_old == "RUNNING" or state_new == "RUNNING"
 
     // Step: stop the container (whichever name it currently has) if running.
     if state_old == "RUNNING"
@@ -1120,7 +1119,11 @@
 
     // Step: host repo dir (coupled only).
     if coupled
-        if paths.is_dir(old_dir) and not paths.is_dir(new_dir)
+        if paths.is_dir(old_dir) and paths.is_dir(new_dir)
+            log.write("repoman: error: both repo dirs exist: " + old_dir + " and " + new_dir)
+            log.write("hint: remove or merge one, then re-run 'repoman rename " + old + " " + new_name + "'")
+            return 1
+        elif paths.is_dir(old_dir)
             log.write("==> mv " + old_dir + " -> " + new_dir)
             let mv_r = iofile.rename(old_dir, new_dir)
             if rg.is_err(mv_r)
@@ -1191,8 +1194,15 @@
         end if
     end if
 
-    // Step: restart if it was running before.
-    if was_running
+    // Step: ensure the container ends running. repoman containers are meant to
+    // be up; this also makes a resumed run bring a stopped container back up
+    // regardless of where a prior run was interrupted.
+    let final_state_r = incus.container_state(inc_project, new_name)
+    mut final_state: string = "MISSING"
+    if rg.is_ok(final_state_r)
+        final_state = rg.unwrap_ok(final_state_r)
+    end if
+    if final_state != "MISSING" and final_state != "RUNNING"
         log.write("==> incus start " + new_name)
         let st_r = incus.start(inc_project, new_name)
         if rg.is_err(st_r)