mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
* fix(ota): isolate updates in persistent workspaces Stage online and offline update archives under /root/.kvmcache/nanokvm-update-* and validate storage, manifests, and archive contents before changing the installed application. * fix(ota): harden storage safety and release gates Preserve the last rollback backup when update storage is insufficient, and verify the actual application mount point before installation. Move the shared transfer sentinel from /tmp to /run, enforce device package limits in release verification, and run that verification in package CI.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package application
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestWorkspaceCleanupIsScopedToUpdaterDirectories(t *testing.T) {
|
|
base := t.TempDir()
|
|
for _, name := range []string{"nanokvm-update-old", "update-other", "firmware.tar.xz", "nanokvm-go_1.0.0"} {
|
|
if err := os.Mkdir(filepath.Join(base, name), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := cleanupStaleWorkspaces(base); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(base, "nanokvm-update-old")); !os.IsNotExist(err) {
|
|
t.Fatalf("stale workspace still exists: %v", err)
|
|
}
|
|
for _, name := range []string{"update-other", "firmware.tar.xz", "nanokvm-go_1.0.0"} {
|
|
if _, err := os.Stat(filepath.Join(base, name)); err != nil {
|
|
t.Fatalf("unrelated cache entry %s was removed: %v", name, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNewWorkspaceIsPrivateAndCloseOnlyRemovesItself(t *testing.T) {
|
|
base := t.TempDir()
|
|
keep := filepath.Join(base, "keep")
|
|
if err := os.WriteFile(keep, []byte("keep"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
workspace, err := newUpdateWorkspace(base)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if filepath.Dir(workspace.dir) != base || !strings.HasPrefix(filepath.Base(workspace.dir), updateWorkspacePrefix) {
|
|
t.Fatalf("unexpected workspace path %q", workspace.dir)
|
|
}
|
|
if err := workspace.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(keep); err != nil {
|
|
t.Fatalf("unrelated cache entry was removed: %v", err)
|
|
}
|
|
}
|