(ctx context.Context, opts *Opts)
| 126 | } |
| 127 | |
| 128 | func NewClient(ctx context.Context, opts *Opts) (*Client, error) { |
| 129 | if opts.imageExportWriter == nil { |
| 130 | imageWriter, err := imageexport.NewWriter(imageexport.WriterOpt{ |
| 131 | Snapshotter: opts.Snapshotter, |
| 132 | ContentStore: opts.ContentStore, |
| 133 | Applier: opts.Applier, |
| 134 | Differ: opts.Differ, |
| 135 | }) |
| 136 | if err != nil { |
| 137 | return nil, fmt.Errorf("create image writer: %w", err) |
| 138 | } |
| 139 | opts.imageExportWriter = imageWriter |
| 140 | } |
| 141 | if opts.running == nil { |
| 142 | opts.running = make(map[string]*execState) |
| 143 | } |
| 144 | if opts.runningMu == nil { |
| 145 | opts.runningMu = &sync.RWMutex{} |
| 146 | } |
| 147 | if opts.GetHostServiceCaller == nil { |
| 148 | opts.GetHostServiceCaller = opts.GetClientCaller |
| 149 | } |
| 150 | |
| 151 | // override the outer cancel, we will manage cancellation ourselves here |
| 152 | ctx, cancel := context.WithCancelCause(context.WithoutCancel(ctx)) |
| 153 | client := &Client{ |
| 154 | Opts: opts, |
| 155 | closeCtx: ctx, |
| 156 | cancel: cancel, |
| 157 | } |
| 158 | |
| 159 | return client, nil |
| 160 | } |
| 161 | |
| 162 | func (opts *Opts) Close() error { |
| 163 | if opts == nil { |
no test coverage detected