Recv sets up the receiving half of the websocket to rsync (the other half set up by rsync.Send), putting the contents in the directory specified by path.
(path string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker, features []string)
| 308 | // half set up by rsync.Send), putting the contents in the directory specified |
| 309 | // by path. |
| 310 | func Recv(path string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker, features []string) error { |
| 311 | args := []string{ |
| 312 | "--server", |
| 313 | "-vlogDtpre.iLsfx", |
| 314 | "--numeric-ids", |
| 315 | "--devices", |
| 316 | "--partial", |
| 317 | "--sparse", |
| 318 | // This flag is only required on the receiving end. |
| 319 | // Checks for file modifications on nanoseconds granularity. |
| 320 | "--modify-window=-1", |
| 321 | } |
| 322 | |
| 323 | if len(features) > 0 { |
| 324 | args = append(args, rsyncFeatureArgs(features)...) |
| 325 | } |
| 326 | |
| 327 | args = append(args, []string{".", path}...) |
| 328 | |
| 329 | cmd := exec.Command("rsync", args...) |
| 330 | |
| 331 | // Call the wrapper if defined. |
| 332 | if RunWrapper != nil { |
| 333 | cleanup, err := RunWrapper(cmd, "", path) |
| 334 | if err != nil { |
| 335 | return err |
| 336 | } |
| 337 | |
| 338 | defer cleanup() |
| 339 | } |
| 340 | |
| 341 | // Forward from rsync to source. |
| 342 | stdout, err := cmd.StdoutPipe() |
| 343 | if err != nil { |
| 344 | return err |
| 345 | } |
| 346 | |
| 347 | chCopyRsync := make(chan error, 1) |
| 348 | go func() { |
| 349 | _, err := util.SafeCopy(conn, stdout) |
| 350 | _ = stdout.Close() |
| 351 | _ = conn.Close() // sends barrier message. |
| 352 | chCopyRsync <- err |
| 353 | }() |
| 354 | |
| 355 | // Forward from source to rsync. |
| 356 | stdin, err := cmd.StdinPipe() |
| 357 | if err != nil { |
| 358 | return err |
| 359 | } |
| 360 | |
| 361 | readSourcePipe := io.ReadCloser(conn) |
| 362 | if tracker != nil { |
| 363 | readSourcePipe = &ioprogress.ProgressReader{ |
| 364 | ReadCloser: conn, |
| 365 | Tracker: tracker, |
| 366 | } |
| 367 | } |
no test coverage detected
searching dependent graphs…