From 6fc2edf7b8a4bd7da9c047f522f44ab3dbb35340 Mon Sep 17 00:00:00 2001 From: Brian Ketelsen Date: Fri, 16 Feb 2024 13:47:59 -0500 Subject: [PATCH] fix: linting errors --- .vscode/settings.json | 6 ++++++ cmd/layer/getProperty/getProperty.go | 2 +- cmd/layer/initcmd/init.go | 2 +- cmd/layer/remove/remove.go | 6 +++++- cmd/mount/path/path.go | 11 ++++++----- cmd/mount/store/store.go | 24 ++++++++++++++++++++---- pkg/logging/userHandler.go | 22 ---------------------- 7 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d126bda --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "go.lintTool": "golangci-lint", + "go.lintFlags": [ + "--fast" + ] +} \ No newline at end of file diff --git a/cmd/layer/getProperty/getProperty.go b/cmd/layer/getProperty/getProperty.go index 233866a..c4b6ae1 100644 --- a/cmd/layer/getProperty/getProperty.go +++ b/cmd/layer/getProperty/getProperty.go @@ -48,7 +48,7 @@ func remove(slice []string, s int) []string { func getPropertyCmd(cmd *cobra.Command, args []string) error { var ( - target_layer string = "" + target_layer string config_file_path string raw_configuration []byte unmarshalled_config = &internal.LayerConfiguration{} diff --git a/cmd/layer/initcmd/init.go b/cmd/layer/initcmd/init.go index 2f1320f..ac062fe 100644 --- a/cmd/layer/initcmd/init.go +++ b/cmd/layer/initcmd/init.go @@ -40,7 +40,7 @@ var defaultConfiguration = &internal.LayerConfiguration{ } func initCmd(cmd *cobra.Command, args []string) error { - var json_config *[]byte = nil + var json_config *[]byte if *fTemplate == "" { slog.Debug("Using default template") var err error diff --git a/cmd/layer/remove/remove.go b/cmd/layer/remove/remove.go index db18605..3b39a57 100644 --- a/cmd/layer/remove/remove.go +++ b/cmd/layer/remove/remove.go @@ -11,7 +11,7 @@ import ( "github.com/ublue-os/bext/internal" "github.com/ublue-os/bext/pkg/fileio" "github.com/ublue-os/bext/pkg/logging" - "github.com/ublue-os/bext/pkg/percentmanager" + percent "github.com/ublue-os/bext/pkg/percentmanager" ) var RemoveCmd = &cobra.Command{ @@ -32,6 +32,10 @@ func init() { } func removeCmd(cmd *cobra.Command, args []string) error { + + // todo dryrun flag + slog.Info("Ignoring dryrun flag", "dryrun", fDryRun) + pw := percent.NewProgressWriter() if !*internal.Config.NoProgress { go pw.Render() diff --git a/cmd/mount/path/path.go b/cmd/mount/path/path.go index 0e191fd..f616954 100644 --- a/cmd/mount/path/path.go +++ b/cmd/mount/path/path.go @@ -1,14 +1,15 @@ package path import ( - "github.com/spf13/cobra" - "github.com/ublue-os/bext/internal" "log/slog" "os" "path" "path/filepath" "strings" "syscall" + + "github.com/spf13/cobra" + "github.com/ublue-os/bext/internal" ) var PathCmd = &cobra.Command{ @@ -65,7 +66,7 @@ func pathCmd(cmd *cobra.Command, args []string) error { mount_path := path.Join(extensions_mount, layers[0].Name(), "bin") if _, err := os.Stat(path_path); err == nil { slog.Debug("Unmounting", slog.String("path", path_path)) - syscall.Unmount(path_path, 0) + _ = syscall.Unmount(path_path, 0) } if err := syscall.Mount(mount_path, path_path, "bind", uintptr(syscall.MS_BIND|syscall.MS_RDONLY), ""); err != nil { return err @@ -73,10 +74,10 @@ func pathCmd(cmd *cobra.Command, args []string) error { } else { if _, err := os.Stat(path_path); err == nil { slog.Debug("Unmounting", slog.String("path", path_path)) - syscall.Unmount(path_path, 0) + _ = syscall.Unmount(path_path, 0) } - syscall.Unmount(path_path, 0) + _ = syscall.Unmount(path_path, 0) err = syscall.Mount("none", path_path, "overlayfs", uintptr(syscall.MS_RDONLY|syscall.MS_NODEV|syscall.MS_NOATIME), "lowerdir="+strings.Join(valid_layers, ":")) if err != nil { return err diff --git a/cmd/mount/store/store.go b/cmd/mount/store/store.go index 3619544..f7d4533 100644 --- a/cmd/mount/store/store.go +++ b/cmd/mount/store/store.go @@ -35,6 +35,9 @@ func storeCmd(cmd *cobra.Command, args []string) error { return err } + // todo refresh flag + slog.Info("Ignoring refresh flag", "refresh", fRefreshStore) + if *internal.Config.UnmountFlag { slog.Debug("Unmounting store", slog.String("target", "/nix/store")) if err := syscall.Unmount("/nix/store", 0); err != nil { @@ -57,11 +60,17 @@ func storeCmd(cmd *cobra.Command, args []string) error { defer root_dir.Close() slog.Debug("Creating nix store", slog.String("target", "/nix/store")) - chattr.SetAttr(root_dir, chattr.FS_IMMUTABLE_FL) + err = chattr.SetAttr(root_dir, chattr.FS_IMMUTABLE_FL) + if err != nil { + return err + } if err := os.Mkdir("/nix/store", 0755); err != nil { return err } - chattr.UnsetAttr(root_dir, chattr.FS_IMMUTABLE_FL) + err = chattr.UnsetAttr(root_dir, chattr.FS_IMMUTABLE_FL) + if err != nil { + return err + } } store_contents, err := os.ReadDir("/nix/store") @@ -74,8 +83,15 @@ func storeCmd(cmd *cobra.Command, args []string) error { return err } - syscall.Unmount("/nix/store", 0) - syscall.Unmount(bindmount_path, 0) + err = syscall.Unmount("/nix/store", 0) + if err != nil { + return err + } + + err = syscall.Unmount(bindmount_path, 0) + if err != nil { + return err + } slog.Debug("Mounting store to itself", slog.String("source", "/nix/store"), slog.String("target", bindmount_path)) if err := syscall.Mount("/nix/store", bindmount_path, "bind", uintptr(syscall.MS_BIND), ""); err != nil { diff --git a/pkg/logging/userHandler.go b/pkg/logging/userHandler.go index c98fd97..e21ce23 100644 --- a/pkg/logging/userHandler.go +++ b/pkg/logging/userHandler.go @@ -3,7 +3,6 @@ package logging import ( "bytes" "context" - "encoding/json" "fmt" "log/slog" "strconv" @@ -78,27 +77,6 @@ func (h *UserHandler) WithGroup(name string) slog.Handler { return &UserHandler{h: h.h.WithGroup(name), b: h.b, m: h.m} } -func (h *UserHandler) computeAttrs( - ctx context.Context, - r slog.Record, -) (map[string]any, error) { - h.m.Lock() - defer func() { - h.b.Reset() - h.m.Unlock() - }() - if err := h.h.Handle(ctx, r); err != nil { - return nil, fmt.Errorf("error when calling inner handler's Handle: %w", err) - } - - var attrs map[string]any - err := json.Unmarshal(h.b.Bytes(), &attrs) - if err != nil { - return nil, fmt.Errorf("error when unmarshaling inner handler's Handle result: %w", err) - } - return attrs, nil -} - func suppressDefaults( next func([]string, slog.Attr) slog.Attr, ) func([]string, slog.Attr) slog.Attr {