fix: lint issues

This commit is contained in:
Yiyang Kang 2022-10-07 02:09:35 +08:00
parent 3464f9a0f5
commit 7e5ba94235
Signed by: kkyy
GPG Key ID: 80FD317ECAF06CC3
4 changed files with 13 additions and 23 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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) {

View File

@ -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)