forked from RepoMirrors/btrfs
refactor ListSubvolumes
This commit is contained in:
parent
7eae92f571
commit
8f48d3ebf5
19
btrfs.go
19
btrfs.go
@ -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 (
|
||||
|
@ -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)
|
||||
|
21
subvolume.go
21
subvolume.go
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user