carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "errors"
7 "os"
8 "path/filepath"
9 "testing"
10
11 "golang.org/x/sys/unix"
12)
13
14// On a kernel without openat2 the removal refuses and leaves the tree: there
15// is no path-based fallback.
16func TestInstallChannelRemovalRefusesWithoutOpenat2(t *testing.T) {
17 f := newChannelFixture(t, "v1.2.0")
18 entry := filepath.Join(f.a.dataDir, "system", "router", "v1.4.0")
19 if err := os.MkdirAll(entry, 0o755); err != nil {
20 t.Fatal(err)
21 }
22 if err := os.WriteFile(filepath.Join(entry, "carlos"), []byte("x"), 0o755); err != nil {
23 t.Fatal(err)
24 }
25 real := openat2
26 defer func() { openat2 = real }()
27 for _, refuse := range []error{unix.ENOSYS, unix.EPERM, unix.EXDEV} {
28 openat2 = func(int, string, *unix.OpenHow) (int, error) { return -1, refuse }
29 if err := removeCacheEntry(f.a.dataDir, "v1.4.0"); !errors.Is(err, refuse) {
30 t.Fatalf("removal with openat2 failing %v: %v", refuse, err)
31 }
32 if _, err := os.Stat(filepath.Join(entry, "carlos")); err != nil {
33 t.Fatalf("the tree was removed without openat2: %v", err)
34 }
35 }
36}
37