(ctx context.Context, stateDir string)
| 63 | } |
| 64 | |
| 65 | func (m *ShimManager) loadShims(ctx context.Context, stateDir string) error { |
| 66 | ns, err := namespaces.NamespaceRequired(ctx) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | ctx = log.WithLogger(ctx, log.G(ctx).WithField("namespace", ns)) |
| 71 | |
| 72 | shimDirs, err := os.ReadDir(filepath.Join(stateDir, ns)) |
| 73 | if err != nil { |
| 74 | return err |
| 75 | } |
| 76 | eg, ctx2 := errgroup.WithContext(ctx) |
| 77 | eg.SetLimit(runtime.GOMAXPROCS(0)) |
| 78 | var errLoad error |
| 79 | for _, sd := range shimDirs { |
| 80 | if !sd.IsDir() { |
| 81 | continue |
| 82 | } |
| 83 | id := sd.Name() |
| 84 | // skip hidden directories |
| 85 | if len(id) > 0 && id[0] == '.' { |
| 86 | continue |
| 87 | } |
| 88 | bundle, err := LoadBundle(ctx, stateDir, id) |
| 89 | if err != nil { |
| 90 | errLoad = err |
| 91 | // fine to return error here, it is a programmer error if the context |
| 92 | // does not have a namespace |
| 93 | break |
| 94 | } |
| 95 | eg.Go(func() error { |
| 96 | // fast path |
| 97 | f, err := os.Open(bundle.Path) |
| 98 | if err != nil { |
| 99 | bundle.Delete() |
| 100 | log.G(ctx2).WithError(err).Errorf("fast path read bundle path for %s", bundle.Path) |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | bf, err := f.Readdirnames(-1) |
| 105 | f.Close() |
| 106 | if err != nil { |
| 107 | bundle.Delete() |
| 108 | log.G(ctx2).WithError(err).Errorf("fast path read bundle path for %s", bundle.Path) |
| 109 | return nil |
| 110 | } |
| 111 | if len(bf) == 0 { |
| 112 | bundle.Delete() |
| 113 | return nil |
| 114 | } |
| 115 | if err := m.loadShim(ctx2, bundle); err != nil { |
| 116 | log.G(ctx2).WithError(err).Errorf("failed to load shim %s", bundle.Path) |
| 117 | bundle.Delete() |
| 118 | return nil |
| 119 | } |
| 120 | return nil |
| 121 | }) |
| 122 | } |
no test coverage detected