MCPcopy
hub / github.com/containerd/containerd / NewBinaryProcessor

Function NewBinaryProcessor

core/diff/stream_windows.go:40–111  ·  view source on GitHub ↗

NewBinaryProcessor returns a binary processor for use with processing content streams

(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args, env []string, payload typeurl.Any)

Source from the content-addressed store, hash-verified

38
39// NewBinaryProcessor returns a binary processor for use with processing content streams
40func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProcessor, name string, args, env []string, payload typeurl.Any) (StreamProcessor, error) {
41 cmd := exec.CommandContext(ctx, name, args...)
42 cmd.Env = os.Environ()
43 cmd.Env = append(cmd.Env, env...)
44
45 if payload != nil {
46 pb := typeurl.MarshalProto(payload)
47 data, err := proto.Marshal(pb)
48 if err != nil {
49 return nil, err
50 }
51 up, err := getUiqPath()
52 if err != nil {
53 return nil, err
54 }
55 path := fmt.Sprintf("\\\\.\\pipe\\containerd-processor-%s-pipe", up)
56 l, err := winio.ListenPipe(path, nil)
57 if err != nil {
58 return nil, err
59 }
60 go func() {
61 defer l.Close()
62 conn, err := l.Accept()
63 if err != nil {
64 log.G(ctx).WithError(err).Error("accept npipe connection")
65 return
66 }
67 io.Copy(conn, bytes.NewReader(data))
68 conn.Close()
69 }()
70 cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", processorPipe, path))
71 }
72 cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", mediaTypeEnvVar, imt))
73 var (
74 stdin io.Reader
75 closer func() error
76 err error
77 )
78 if f, ok := stream.(RawProcessor); ok {
79 stdin = f.File()
80 closer = f.File().Close
81 } else {
82 stdin = stream
83 }
84 cmd.Stdin = stdin
85 r, w, err := os.Pipe()
86 if err != nil {
87 return nil, err
88 }
89 cmd.Stdout = w
90 stderr := bytes.NewBuffer(nil)
91 cmd.Stderr = stderr
92
93 if err := cmd.Start(); err != nil {
94 return nil, err
95 }
96 p := &binaryProcessor{
97 cmd: cmd,

Callers

nothing calls this directly

Calls 9

waitMethod · 0.95
MarshalFunction · 0.92
getUiqPathFunction · 0.85
CopyMethod · 0.80
PipeMethod · 0.80
CloseMethod · 0.65
FileMethod · 0.65
StartMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…