Skip to content

Commit

Permalink
fix ignoring zfs create error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dmke committed Aug 20, 2024
1 parent 7ddf8e7 commit 8c3a2f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 1 addition & 14 deletions zfs/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zfs

import (
"bytes"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -213,14 +212,7 @@ func DoSync(from, to *Fs, flags Flags) error {
// ensure the filesystem exists
toChild, err := to.CreateIfMissing(fromChild.name)
if err != nil {
var exitErr *exec.ExitError
ignore := false
if errors.As(err, &exitErr) {
ignore = canIgnoreCreateError(string(exitErr.Stderr))
}
if !ignore {
return err
}
return err
}
err = DoSync(fromChild, toChild, flags)
if err != nil {
Expand All @@ -231,8 +223,3 @@ func DoSync(from, to *Fs, flags Flags) error {

return nil
}

func canIgnoreCreateError(msg string) bool {
return strings.Contains(msg, "successfully created, but not mounted") ||
strings.Contains(msg, "filesystem successfully created, but it may only be mounted by root")
}
11 changes: 11 additions & 0 deletions zfs/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,20 @@ func (z *Zfs) parseList(b []byte) *Fs {
return root
}

func canIgnoreCreateError(msg string) bool {
return strings.Contains(msg, "successfully created, but not mounted") ||
strings.Contains(msg, "filesystem successfully created, but it may only be mounted by root")
}

// Create creates a new filesystem by its full path.
func (z *Zfs) Create(fs string) error {
_, err := z.exec("/sbin/zfs", "create", fs).Output()

var exitErr *exec.ExitError
if errors.As(err, &exitErr) && canIgnoreCreateError(string(exitErr.Stderr)) {
return nil
}

return err
}

Expand Down

0 comments on commit 8c3a2f4

Please sign in to comment.