Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Merge pull request #18 from ublue-os/linter
Browse files Browse the repository at this point in the history
fix: linting errors
  • Loading branch information
bketelsen authored Feb 16, 2024
2 parents 081abf6 + 6fc2edf commit ff5fd54
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
}
2 changes: 1 addition & 1 deletion cmd/layer/getProperty/getProperty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/layer/initcmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cmd/layer/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions cmd/mount/path/path.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down Expand Up @@ -65,18 +66,18 @@ 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
}
} 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
Expand Down
24 changes: 20 additions & 4 deletions cmd/mount/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
22 changes: 0 additions & 22 deletions pkg/logging/userHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package logging
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log/slog"
"strconv"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ff5fd54

Please sign in to comment.