Write down what an archive unpacked as soon as it is unpacked, so a lost record never makes the host's own files foreign (issue 1585)

Claude-Session: https://claude.ai/code/session_01JG73KG7AfSdh6FP8VrBqCn
This commit is contained in:
2026-11-04 10:26:43 +01:00
parent fabfdf04f7
commit 84a14b08d5
5 changed files with 209 additions and 3 deletions
+15 -2
View File
@@ -3,6 +3,7 @@ package apply
import (
"context"
"os"
"strings"
"testing"
"github.com/novox/mesh-host/internal/store"
@@ -32,7 +33,7 @@ func TestAnArchiveReplacesTheTreeItWasUnpackedOver(t *testing.T) {
if _, err := os.Stat(dir + "/tools/node_modules"); err == nil {
t.Fatal("the previous archive's directory is still there")
}
entries, _ := os.ReadDir(dir)
entries := besideTheTree(dir)
if len(entries) != 1 {
names := []string{}
for _, e := range entries {
@@ -62,7 +63,19 @@ func TestARefusedArchiveLeavesTheTreeItWouldHaveReplaced(t *testing.T) {
if got, _ := os.ReadFile(dir + "/tools/index.js"); string(got) != "old" {
t.Fatalf("index.js is %q after a refused archive", got)
}
if entries, _ := os.ReadDir(dir); len(entries) != 1 {
if entries := besideTheTree(dir); len(entries) != 1 {
t.Fatalf("%d entries beside the tree after a refused archive", len(entries))
}
}
// besideTheTree is what sits in dir, but for the journals of what archives unpacked (novox/hq issue 1585).
func besideTheTree(dir string) []os.DirEntry {
all, _ := os.ReadDir(dir)
var out []os.DirEntry
for _, e := range all {
if !strings.HasSuffix(e.Name(), journalSuffix) {
out = append(out, e)
}
}
return out
}