mirror of
https://github.com/dennwc/btrfs
synced 2025-01-10 00:59:23 +00:00
b300237e77
* better code generator * regenerate btrfs_tree.h constants * implement subvolume create, delete and snapshot create commands * exec-based snapshot send and receive
33 lines
555 B
Go
33 lines
555 B
Go
package btrfs
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
"os/exec"
|
|
)
|
|
|
|
func Receive(r io.Reader, mount string) error {
|
|
// TODO: write a native implementation?
|
|
//tf, err := ioutil.TempFile("","btrfs_snap")
|
|
//if err != nil {
|
|
// return err
|
|
//}
|
|
//defer func(){
|
|
// name := tf.Name()
|
|
// tf.Close()
|
|
// os.Remove(name)
|
|
//}()
|
|
buf := bytes.NewBuffer(nil)
|
|
cmd := exec.Command("btrfs", "receive", mount)
|
|
cmd.Stdin = r
|
|
cmd.Stderr = buf
|
|
if err := cmd.Run(); err != nil {
|
|
if buf.Len() != 0 {
|
|
return errors.New(buf.String())
|
|
}
|
|
return err
|
|
}
|
|
return nil
|
|
}
|