Skip to content

Merge others work #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,13 @@ func parseInodeChanges(lines [][]string) ([]*InodeChange, error) {
return changes, nil
}

func listByType(t, filter string) ([]*Dataset, error) {
args := []string{"get", "-rHp", "-t", t, "all"}
func listByType(t, filter string, depth int) ([]*Dataset, error) {
var args []string
if depth > 0 {
args = []string{"get", fmt.Sprintf("-d%d", depth), "-rHp", "-t", t, "all"}
} else {
args = []string{"get", "-rHp", "-t", t, "all"}
}
if filter != "" {
args = append(args, filter)
}
Expand Down
18 changes: 9 additions & 9 deletions zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,29 @@ func zfs(arg ...string) ([][]string, error) {
// Datasets returns a slice of ZFS datasets, regardless of type.
// A filter argument may be passed to select a dataset with the matching name,
// or empty string ("") may be used to select all datasets.
func Datasets(filter string) ([]*Dataset, error) {
return listByType("all", filter)
func Datasets(filter string, depth int) ([]*Dataset, error) {
return listByType("all", filter, depth)
}

// Snapshots returns a slice of ZFS snapshots.
// A filter argument may be passed to select a snapshot with the matching name,
// or empty string ("") may be used to select all snapshots.
func Snapshots(filter string) ([]*Dataset, error) {
return listByType(DatasetSnapshot, filter)
func Snapshots(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetSnapshot, filter, depth)
}

// Filesystems returns a slice of ZFS filesystems.
// A filter argument may be passed to select a filesystem with the matching name,
// or empty string ("") may be used to select all filesystems.
func Filesystems(filter string) ([]*Dataset, error) {
return listByType(DatasetFilesystem, filter)
func Filesystems(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetFilesystem, filter, depth)
}

// Volumes returns a slice of ZFS volumes.
// A filter argument may be passed to select a volume with the matching name,
// or empty string ("") may be used to select all volumes.
func Volumes(filter string) ([]*Dataset, error) {
return listByType(DatasetVolume, filter)
func Volumes(filter string, depth int) ([]*Dataset, error) {
return listByType(DatasetVolume, filter, depth)
}

// GetDataset retrieves a single ZFS dataset by name. This dataset could be
Expand Down Expand Up @@ -337,7 +337,7 @@ func (d *Dataset) Rename(name string, createParent bool, recursiveRenameSnapshot

// Snapshots returns a slice of all ZFS snapshots of a given dataset.
func (d *Dataset) Snapshots() ([]*Dataset, error) {
return Snapshots(d.Name)
return Snapshots(d.Name, 1)
}

// CreateFilesystem creates a new ZFS filesystem with the specified name and
Expand Down
21 changes: 10 additions & 11 deletions zfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func zpoolTest(t *testing.T, fn func()) {

func TestDatasets(t *testing.T) {
zpoolTest(t, func() {
_, err := zfs.Datasets("")
_, err := zfs.Datasets("", 1)
ok(t, err)

ds, err := zfs.GetDataset("test")
Expand All @@ -85,7 +85,7 @@ func TestDatasets(t *testing.T) {
func TestSnapshots(t *testing.T) {

zpoolTest(t, func() {
snapshots, err := zfs.Snapshots("")
snapshots, err := zfs.Snapshots("", 1)
ok(t, err)

for _, snapshot := range snapshots {
Expand All @@ -99,7 +99,7 @@ func TestFilesystems(t *testing.T) {
f, err := zfs.CreateFilesystem("test/filesystem-test", nil)
ok(t, err)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand All @@ -121,7 +121,7 @@ func TestCreateFilesystemWithProperties(t *testing.T) {

equals(t, "lz4", f.Compression)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand All @@ -141,7 +141,7 @@ func TestVolumes(t *testing.T) {
sleep(1)

equals(t, zfs.DatasetVolume, v.Type)
volumes, err := zfs.Volumes("")
volumes, err := zfs.Volumes("", 1)
ok(t, err)

for _, volume := range volumes {
Expand All @@ -157,7 +157,7 @@ func TestSnapshot(t *testing.T) {
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
ok(t, err)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand All @@ -182,7 +182,7 @@ func TestClone(t *testing.T) {
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
ok(t, err)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestSendSnapshot(t *testing.T) {
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
ok(t, err)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand Down Expand Up @@ -264,8 +264,7 @@ func TestListZpool(t *testing.T) {
zpoolTest(t, func() {
pools, err := zfs.ListZpools()
ok(t, err)
equals(t, "test", pools[0].Name)

equals(t, true, len(pools)>0)
})
}

Expand All @@ -274,7 +273,7 @@ func TestRollback(t *testing.T) {
f, err := zfs.CreateFilesystem("test/snapshot-test", nil)
ok(t, err)

filesystems, err := zfs.Filesystems("")
filesystems, err := zfs.Filesystems("", 1)
ok(t, err)

for _, filesystem := range filesystems {
Expand Down
8 changes: 4 additions & 4 deletions zpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func GetZpool(name string) (*Zpool, error) {
}

// Datasets returns a slice of all ZFS datasets in a zpool.
func (z *Zpool) Datasets() ([]*Dataset, error) {
return Datasets(z.Name)
func (z *Zpool) Datasets(depth int) ([]*Dataset, error) {
return Datasets(z.Name, depth)
}

// Snapshots returns a slice of all ZFS snapshots in a zpool.
func (z *Zpool) Snapshots() ([]*Dataset, error) {
return Snapshots(z.Name)
func (z *Zpool) Snapshots(depth int) ([]*Dataset, error) {
return Snapshots(z.Name, depth)
}

// CreateZpool creates a new ZFS zpool with the specified name, properties,
Expand Down