Skip to content

Commit 8c3a2f4

Browse files
committed
fix ignoring zfs create error messages
1 parent 7ddf8e7 commit 8c3a2f4

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

zfs/transfer.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package zfs
22

33
import (
44
"bytes"
5-
"errors"
65
"fmt"
76
"io"
87
"log"
@@ -213,14 +212,7 @@ func DoSync(from, to *Fs, flags Flags) error {
213212
// ensure the filesystem exists
214213
toChild, err := to.CreateIfMissing(fromChild.name)
215214
if err != nil {
216-
var exitErr *exec.ExitError
217-
ignore := false
218-
if errors.As(err, &exitErr) {
219-
ignore = canIgnoreCreateError(string(exitErr.Stderr))
220-
}
221-
if !ignore {
222-
return err
223-
}
215+
return err
224216
}
225217
err = DoSync(fromChild, toChild, flags)
226218
if err != nil {
@@ -231,8 +223,3 @@ func DoSync(from, to *Fs, flags Flags) error {
231223

232224
return nil
233225
}
234-
235-
func canIgnoreCreateError(msg string) bool {
236-
return strings.Contains(msg, "successfully created, but not mounted") ||
237-
strings.Contains(msg, "filesystem successfully created, but it may only be mounted by root")
238-
}

zfs/zfs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,20 @@ func (z *Zfs) parseList(b []byte) *Fs {
7575
return root
7676
}
7777

78+
func canIgnoreCreateError(msg string) bool {
79+
return strings.Contains(msg, "successfully created, but not mounted") ||
80+
strings.Contains(msg, "filesystem successfully created, but it may only be mounted by root")
81+
}
82+
7883
// Create creates a new filesystem by its full path.
7984
func (z *Zfs) Create(fs string) error {
8085
_, err := z.exec("/sbin/zfs", "create", fs).Output()
86+
87+
var exitErr *exec.ExitError
88+
if errors.As(err, &exitErr) && canIgnoreCreateError(string(exitErr.Stderr)) {
89+
return nil
90+
}
91+
8192
return err
8293
}
8394

0 commit comments

Comments
 (0)