mirror of
https://github.com/dennwc/btrfs
synced 2025-03-11 06:48:27 +00:00
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))
|
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
|
type Compression string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -74,7 +74,12 @@ var SubvolumeListCmd = &cobra.Command{
|
|||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
return fmt.Errorf("expected one destination argument")
|
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 {
|
if err == nil {
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
fmt.Printf("%+v\n", v)
|
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
|
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 {
|
type Subvolume struct {
|
||||||
ObjectID uint64
|
ObjectID uint64
|
||||||
TransID uint64
|
TransID uint64
|
||||||
|
Loading…
Reference in New Issue
Block a user