(path string, parent string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker)
| 347 | } |
| 348 | |
| 349 | func (d *btrfs) sendSubvolume(path string, parent string, conn io.ReadWriteCloser, tracker *ioprogress.ProgressTracker) error { |
| 350 | defer logger.WarnOnError(conn.Close, "Failed to close connection") |
| 351 | |
| 352 | // Assemble btrfs send command. |
| 353 | args := []string{"send"} |
| 354 | if parent != "" { |
| 355 | args = append(args, "-p", parent) |
| 356 | } |
| 357 | |
| 358 | args = append(args, path) |
| 359 | cmd := exec.Command("btrfs", args...) |
| 360 | |
| 361 | stderr, err := cmd.StderrPipe() |
| 362 | if err != nil { |
| 363 | return err |
| 364 | } |
| 365 | |
| 366 | // Setup progress tracker. |
| 367 | var stdout io.WriteCloser = conn |
| 368 | if tracker != nil { |
| 369 | stdout = &ioprogress.ProgressWriter{ |
| 370 | WriteCloser: conn, |
| 371 | Tracker: tracker, |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | cmd.Stdout = stdout |
| 376 | |
| 377 | // Run the command. |
| 378 | err = cmd.Start() |
| 379 | if err != nil { |
| 380 | return err |
| 381 | } |
| 382 | |
| 383 | // Read any error. |
| 384 | output, err := io.ReadAll(stderr) |
| 385 | if err != nil { |
| 386 | logger.Errorf("Problem reading btrfs send stderr: %s", err) |
| 387 | } |
| 388 | |
| 389 | err = cmd.Wait() |
| 390 | if err != nil { |
| 391 | return fmt.Errorf("Btrfs send failed: %w (%s)", err, string(output)) |
| 392 | } |
| 393 | |
| 394 | return nil |
| 395 | } |
| 396 | |
| 397 | // setSubvolumeReadonlyProperty sets the readonly property on the subvolume to true or false. |
| 398 | func (d *btrfs) setSubvolumeReadonlyProperty(path string, readonly bool) error { |
no test coverage detected