Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vansante committed Mar 21, 2024
1 parent f9cec5a commit 4b0833f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 1 addition & 3 deletions job/filesystem_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func TestRunner_pruneFilesystems(t *testing.T) {
ds, err := zfs.GetDataset(context.Background(), testZPool)
require.NoError(t, err)

datasets, err := ds.Children(context.Background(), zfs.ListOptions{
Depth: 1,
})
datasets, err := ds.Children(context.Background(), zfs.ListOptions{})
require.NoError(t, err)
require.Len(t, datasets, 5)
require.Equal(t, fmt.Sprintf("%s/%s", testZPool, fsWithoutDel), datasets[0].Name)
Expand Down
12 changes: 10 additions & 2 deletions job/snapshots_mark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package job

import (
"fmt"
"slices"
"time"

zfs "github.com/vansante/go-zfsutils"
Expand Down Expand Up @@ -66,8 +67,15 @@ func (r *Runner) markExcessDatasetSnapshots(ds *zfs.Dataset, maxCount int64) err
return fmt.Errorf("error retrieving snapshots for %s: %w", ds.Name, err)
}

// ListSnapshots are always retrieved with the newest last, so reverse the list:
reverseDatasets(snaps)
// Sort the list by created, newest first:
snaps, err = orderSnapshotsByCreated(snaps, createdProp)
if err != nil {
return fmt.Errorf("error sorting snapshots for %s: %w", ds.Name, err)
}

// Snapshots are always retrieved with the newest last, so reverse the list:
slices.Reverse(snaps)

currentFound := int64(0)
now := time.Now()
for i := range snaps {
Expand Down
6 changes: 0 additions & 6 deletions job/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ func snapshotsContain(list []zfs.Dataset, dataset, snapshot string) bool {
return false
}

func reverseDatasets(s []zfs.Dataset) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}

// randomizeDuration adds or removes up to 5% of the duration to randomize background routine wake up times
func randomizeDuration(d time.Duration) time.Duration { // nolint:unparam
rnd := time.Duration(rand.Int63n(int64(d / 10)))
Expand Down
1 change: 0 additions & 1 deletion zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func ListDatasets(ctx context.Context, options ListOptions) ([]Dataset, error) {
args = append(args, options.ParentDataset)
}

fmt.Println(strings.Join(args, " "))
out, err := zfsOutput(ctx, args...)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions zfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestDatasetsWithProps(t *testing.T) {

require.Len(t, ds.ExtraProps, 2, fmt.Sprintf("%#v", ds.ExtraProps))
require.Equal(t, "world", ds.ExtraProps["nl.test:hello"])
require.Equal(t, "off", ds.ExtraProps["canmount"])
require.Equal(t, "on", ds.ExtraProps["canmount"])
})
}

Expand Down Expand Up @@ -226,7 +226,7 @@ func TestListWithProperty(t *testing.T) {
TestZPool(testZPool, func() {
const prop = "nl.test:bla"

f1, err := CreateFilesystem(context.Background(), testZPool+"/list-test1", CreateFilesystemOptions{
f1, err := CreateFilesystem(context.Background(), testZPool+"/list-test", CreateFilesystemOptions{
Properties: noMountProps,
})
require.NoError(t, err)
Expand Down

0 comments on commit 4b0833f

Please sign in to comment.