fix: lint issues
This commit is contained in:
parent
3464f9a0f5
commit
7e5ba94235
|
@ -97,7 +97,7 @@ type Mounter struct {
|
|||
}
|
||||
|
||||
func NewMounterFromPreset(p *mnt.Preset) (mnt.Mounter, error) {
|
||||
preset := &*p
|
||||
preset := *p
|
||||
if preset.Path == "" {
|
||||
return nil, errors.New("preset path is empty")
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func NewMounterFromPreset(p *mnt.Preset) (mnt.Mounter, error) {
|
|||
return nil, errors.Errorf("invalid mount point %q", preset.MountPoint)
|
||||
}
|
||||
m := &Mounter{
|
||||
preset: preset,
|
||||
preset: &preset,
|
||||
}
|
||||
if err := m.refresh(); err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
|
|
2
main.go
2
main.go
|
@ -69,7 +69,7 @@ func main() {
|
|||
err = mounter.Unmount()
|
||||
}
|
||||
if err != nil {
|
||||
msg.Errorf("%v", mountPoint, err)
|
||||
msg.Errorf("%v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
msg.Infof("Success")
|
||||
|
|
|
@ -110,7 +110,7 @@ func isPgpEncrypted(path string) (bool, error) {
|
|||
return false, errors.Wrap(err, 0)
|
||||
}
|
||||
l, err := script.Echo(string(output)).Match("PGP").Match("encrypted").CountLines()
|
||||
return l > 0, nil
|
||||
return l > 0, err
|
||||
}
|
||||
|
||||
func readPgpEncryptedFile(path string) ([]byte, error) {
|
||||
|
|
28
zfs/zfs.go
28
zfs/zfs.go
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/user"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
@ -22,8 +21,6 @@ import (
|
|||
|
||||
const ZfsBin = "/usr/bin/zfs"
|
||||
|
||||
type execFunc func(string, io.Reader, ...string) ([]byte, error)
|
||||
|
||||
type Permissions struct {
|
||||
Mount bool
|
||||
LoadKey bool
|
||||
|
@ -101,7 +98,8 @@ func (d *Dataset) Permissions() (*Permissions, error) {
|
|||
if err := d.loadPermissions(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &*d.permissions, nil
|
||||
perm := *d.permissions
|
||||
return &perm, nil
|
||||
}
|
||||
|
||||
func listCmd(name string, recursive bool) ([]byte, error) {
|
||||
|
@ -173,12 +171,12 @@ type Mounter struct {
|
|||
}
|
||||
|
||||
func NewMounterFromPreset(p *mnt.Preset) (mnt.Mounter, error) {
|
||||
preset := &*p
|
||||
preset := *p
|
||||
if preset.Path == "" {
|
||||
return nil, errors.New("preset path is empty")
|
||||
}
|
||||
m := &Mounter{
|
||||
preset: preset,
|
||||
preset: &preset,
|
||||
}
|
||||
|
||||
// find the dataset
|
||||
|
@ -224,11 +222,9 @@ func (m *Mounter) loadKey() error {
|
|||
if err != nil {
|
||||
return errors.WrapPrefix(err, "failed to load zfs key", 0)
|
||||
}
|
||||
var run execFunc
|
||||
run := util.RunPrivilegedCommand
|
||||
if perm.LoadKey {
|
||||
run = util.RunCommand
|
||||
} else {
|
||||
run = util.RunPrivilegedCommand
|
||||
}
|
||||
|
||||
msg.Infof("zfs load-key %q", m.dataset.Name)
|
||||
|
@ -263,7 +259,7 @@ func (m *Mounter) mount() error {
|
|||
|
||||
// If systemd mount unit exists, use it.
|
||||
// In this case, if we do not use systemd for mounting, systemd will mess with the mounting process, and the zfs
|
||||
// dataset will get unmounted immediately after mounting. See https://github.com/openzfs/zfs/issues/11248
|
||||
// dataset will get unmounted immediately after we mounted it. See https://github.com/openzfs/zfs/issues/11248
|
||||
if err := util.SystemdMount(mountPoint); err == nil {
|
||||
return nil
|
||||
} else if !util.ShouldSkipSdMount(err) {
|
||||
|
@ -282,11 +278,9 @@ func (m *Mounter) mount() error {
|
|||
if err != nil {
|
||||
return errors.WrapPrefix(err, fmt.Sprintf("failed to mount zfs dataset %q", m.dataset.Name), 0)
|
||||
}
|
||||
var run execFunc
|
||||
run := util.RunPrivilegedCommand
|
||||
if perm.Mount {
|
||||
run = util.RunCommand
|
||||
} else {
|
||||
run = util.RunPrivilegedCommand
|
||||
}
|
||||
|
||||
_, err = run(ZfsBin, nil, mountArgs...)
|
||||
|
@ -338,11 +332,9 @@ func (m *Mounter) unmount() error {
|
|||
if err != nil {
|
||||
return errors.WrapPrefix(err, fmt.Sprintf("failed to unmount zfs dataset %q", m.dataset.Name), 0)
|
||||
}
|
||||
var run execFunc
|
||||
run := util.RunPrivilegedCommand
|
||||
if perm.Mount {
|
||||
run = util.RunCommand
|
||||
} else {
|
||||
run = util.RunPrivilegedCommand
|
||||
}
|
||||
|
||||
_, err = run(ZfsBin, nil, "unmount", "-u", m.dataset.Name)
|
||||
|
@ -361,11 +353,9 @@ func (m *Mounter) unloadKey() error {
|
|||
if err != nil {
|
||||
return errors.WrapPrefix(err, "failed to unload zfs key", 0)
|
||||
}
|
||||
var run execFunc
|
||||
run := util.RunPrivilegedCommand
|
||||
if perm.LoadKey {
|
||||
run = util.RunCommand
|
||||
} else {
|
||||
run = util.RunPrivilegedCommand
|
||||
}
|
||||
|
||||
msg.Infof("zfs unload-key %q", m.dataset.Name)
|
||||
|
|
Loading…
Reference in New Issue