MCPcopy
hub / github.com/lxc/incus / Send

Function Send

internal/rsync/rsync.go:241–305  ·  view source on GitHub ↗

Send sets up the sending half of an rsync, to recursively send the directory pointed to by path over the websocket.

(name string, path string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker, features []string, bwlimit string, execPath string, rsyncArgs ...string)

Source from the content-addressed store, hash-verified

239// Send sets up the sending half of an rsync, to recursively send the
240// directory pointed to by path over the websocket.
241func Send(name string, path string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker, features []string, bwlimit string, execPath string, rsyncArgs ...string) error {
242 cmd, netcatConn, stderr, err := sendSetup(name, path, bwlimit, execPath, features, rsyncArgs...)
243 if err != nil {
244 return err
245 }
246
247 // Setup progress tracker.
248 readNetcatPipe := io.ReadCloser(netcatConn)
249 if tracker != nil {
250 readNetcatPipe = &ioprogress.ProgressReader{
251 ReadCloser: netcatConn,
252 Tracker: tracker,
253 }
254 }
255
256 // Forward from netcat to target.
257 chCopyNetcat := make(chan error, 1)
258 go func() {
259 _, err := util.SafeCopy(conn, readNetcatPipe)
260 chCopyNetcat <- err
261 _ = readNetcatPipe.Close()
262 _ = netcatConn.Close()
263 _ = conn.Close() // sends barrier message.
264 }()
265
266 // Forward from target to netcat.
267 writeNetcatPipe := io.WriteCloser(netcatConn)
268 chCopyTarget := make(chan error, 1)
269 go func() {
270 _, err := util.SafeCopy(writeNetcatPipe, conn)
271 chCopyTarget <- err
272 _ = writeNetcatPipe.Close()
273 }()
274
275 // Wait for rsync to complete.
276 output, err := io.ReadAll(stderr)
277 if err != nil {
278 _ = cmd.Process.Kill()
279 logger.Errorf("Rsync stderr read failed: %s: %v", path, err)
280 }
281
282 err = cmd.Wait()
283 errs := []error{}
284 chCopyNetcatErr := <-chCopyNetcat
285 chCopyTargetErr := <-chCopyTarget
286
287 if err != nil {
288 errs = append(errs, err)
289
290 // Try to get more info about the error.
291 if chCopyNetcatErr != nil {
292 errs = append(errs, chCopyNetcatErr)
293 }
294
295 if chCopyTargetErr != nil {
296 errs = append(errs, chCopyTargetErr)
297 }
298 }

Callers 4

qcow2MigrateVolumeMethod · 0.92
genericVFSMigrateVolumeFunction · 0.92
MigrateSendMethod · 0.92

Calls 7

SafeCopyFunction · 0.92
ErrorfFunction · 0.92
sendSetupFunction · 0.85
ErrorfMethod · 0.80
CloseMethod · 0.65
WaitMethod · 0.65
KillMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…