fix(agent): v0.3.10 cleanup orphan instance dirs on startup

- Add cleanupOrphanInstanceDirs() to remove leftover instance directories
  after failed deletes (common on Windows when compose.log is locked)
- Log RemoveAll errors in dockerComposeRm for better visibility
- Bump version to 0.3.10 and rebuild binaries
This commit is contained in:
EduBox Dev
2026-06-27 21:36:02 +00:00
parent e946b22a42
commit 33d89c66c0
5 changed files with 54 additions and 12 deletions
+32
View File
@@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
@@ -130,3 +131,34 @@ func getInstanceStatus(dataDir, instanceID string) string {
}
return "stopped"
}
// cleanupOrphanInstanceDirs removes instance directories that have no entry in
// instances.json. This typically happens on Windows when a delete operation
// could not fully remove the directory because compose.log was locked.
func cleanupOrphanInstanceDirs(dataDir string) {
instancesDir := filepath.Join(dataDir, "instances")
inst, err := loadInstances(dataDir)
if err != nil {
log.Printf("cleanupOrphanInstanceDirs: loadInstances error: %v", err)
return
}
entries, err := os.ReadDir(instancesDir)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("cleanupOrphanInstanceDirs: ReadDir error: %v", err)
}
return
}
for _, entry := range entries {
if !entry.IsDir() {
continue
}
if _, ok := inst[entry.Name()]; !ok {
dir := filepath.Join(instancesDir, entry.Name())
log.Printf("cleanupOrphanInstanceDirs: removing orphan directory %s", dir)
if err := os.RemoveAll(dir); err != nil {
log.Printf("cleanupOrphanInstanceDirs: RemoveAll error for %s: %v", dir, err)
}
}
}
}