Debian Codegraph @

pin/walk_other.go

raw symbols SCIP
1 //go:build !windows
2
3 package pin
4
5 import (
6 "fmt"
7 "io/fs"
8 "iter"
9 "os"
10 "path/filepath"
11
12 "github.com/cilium/ebpf"
13 "github.com/cilium/ebpf/internal/linux"
14 "github.com/cilium/ebpf/internal/unix"
15 )
16
17 // WalkDir walks the file tree rooted at path and yields a [Pin] for each
18 // BPF object below the path.
19 //
20 // Callers must invoke [Pin.Take] if they wish to hold on to the object.
21 func WalkDir(root string, opts *ebpf.LoadPinOptions) iter.Seq2[*Pin, error] {
22 return func(yield func(*Pin, error) bool) {
23 fsType, err := linux.FSType(root)
24 if err != nil {
25 yield(nil, err)
26 return
27 }
28 if fsType != unix.BPF_FS_MAGIC {
29 yield(nil, fmt.Errorf("%s is not on a bpf filesystem", root))
30 return
31 }
32
33 fn := func(path string, d fs.DirEntry, err error) error {
34 if err != nil {
35 return err
36 }
37
38 if d.IsDir() {
39 return nil
40 }
41
42 path = filepath.Join(root, path)
43 obj, err := Load(path, opts)
44 if err != nil {
45 return err
46 }
47
48 pin := &Pin{Path: path, Object: obj}
49 defer pin.close()
50
51 if !yield(pin, nil) {
52 return fs.SkipAll
53 }
54
55 return nil
56 }
57
58 err = fs.WalkDir(os.DirFS(root), ".", fn)
59 if err != nil {
60 yield(nil, fmt.Errorf("walk: %w", err))
61 return
62 }
63 }
64 }