refactor ListSubvolumes

This commit is contained in:
Denys Smirnov 2016-10-01 15:10:12 +03:00
parent 7eae92f571
commit 8f48d3ebf5
3 changed files with 25 additions and 22 deletions

View File

@ -201,6 +201,25 @@ func (f *FS) ReceiveTo(r io.Reader, mount string) error {
return Receive(r, filepath.Join(f.f.Name(), mount))
}
func (f *FS) ListSubvolumes(filter func(Subvolume) bool) ([]Subvolume, error) {
//root, err := getPathRootID(f)
//if err != nil {
// return nil, fmt.Errorf("can't get rootid for '%s': %v", path, err)
//}
m, err := listSubVolumes(f.f)
if err != nil {
return nil, err
}
out := make([]Subvolume, 0, len(m))
for _, v := range m {
if filter != nil && !filter(v) {
continue
}
out = append(out, v)
}
return out, nil
}
type Compression string
const (

View File

@ -74,7 +74,12 @@ var SubvolumeListCmd = &cobra.Command{
if len(args) != 1 {
return fmt.Errorf("expected one destination argument")
}
list, err := btrfs.ListSubVolumes(args[0])
fs, err := btrfs.Open(args[0], true)
if err != nil {
return err
}
defer fs.Close()
list, err := fs.ListSubvolumes(nil)
if err == nil {
for _, v := range list {
fmt.Printf("%+v\n", v)

View File

@ -146,27 +146,6 @@ func SnapshotSubVolume(subvol, dst string, ro bool) error {
return nil
}
func ListSubVolumes(path string) ([]Subvolume, error) {
f, err := openDir(path)
if err != nil {
return nil, err
}
defer f.Close()
//root, err := getPathRootID(f)
//if err != nil {
// return nil, fmt.Errorf("can't get rootid for '%s': %v", path, err)
//}
m, err := listSubVolumes(f)
if err != nil {
return nil, err
}
out := make([]Subvolume, 0, len(m))
for _, v := range m {
out = append(out, v)
}
return out, nil
}
type Subvolume struct {
ObjectID uint64
TransID uint64