Skip to content

Commit c509027

Browse files
authored
split after \t instead of any spaces (mistifyio#68)
Without this dates like (Wed Feb 21 12:51 2018) in the creation property are split into multiple fields
2 parents 81c92b4 + 8f8b2ca commit c509027

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (c *command) Run(arg ...string) ([][]string, error) {
6161
output := make([][]string, len(lines))
6262

6363
for i, l := range lines {
64-
output[i] = strings.Fields(l)
64+
output[i] = strings.Split(l, "\t")
6565
}
6666

6767
return output, nil

utils_notsolaris.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var (
1515
zpoolPropList = []string{"name", "health", "allocated", "size", "free", "readonly", "dedupratio", "fragmentation", "freeing", "leaked"}
1616

1717
zpoolPropListOptions = strings.Join(zpoolPropList, ",")
18-
zpoolArgs = []string{"get", "-p", zpoolPropListOptions}
18+
zpoolArgs = []string{"get", "-Hp", zpoolPropListOptions}
1919
)

utils_solaris.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var (
1515
zpoolPropList = []string{"name", "health", "allocated", "size", "free", "readonly", "dedupratio"}
1616

1717
zpoolPropListOptions = strings.Join(zpoolPropList, ",")
18-
zpoolArgs = []string{"get", "-p", zpoolPropListOptions}
18+
zpoolArgs = []string{"get", "-Hp", zpoolPropListOptions}
1919
)

zfs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"runtime"
8+
"strings"
89
"testing"
910

1011
zfs "github.com/mistifyio/go-zfs/v3"
@@ -38,6 +39,13 @@ func TestDatasetGetProperty(t *testing.T) {
3839
prop, err = ds.GetProperty("compression")
3940
ok(t, err)
4041
equals(t, "off", prop)
42+
43+
// creation should be a time stamp with spaces in it
44+
prop, err = ds.GetProperty("creation")
45+
ok(t, err)
46+
if len(strings.Fields(prop)) != 5 {
47+
t.Errorf("expected a string with spaces in it, got: %v", prop)
48+
}
4149
}
4250

4351
func TestSnapshots(t *testing.T) {

zpool.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ func GetZpool(name string) (*Zpool, error) {
4949
return nil, err
5050
}
5151

52-
// there is no -H
53-
out = out[1:]
54-
5552
z := &Zpool{Name: name}
5653
for _, line := range out {
5754
if err := z.parseLine(line); err != nil {

0 commit comments

Comments
 (0)