diff --git a/.golangci.yml b/.golangci.yml index 7a700f55691..c141fde60e9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -41,7 +41,7 @@ linters-settings: - name: bool-literal-in-expr - name: cognitive-complexity arguments: - - 36 # TODO: gradually reduce it + - 30 # TODO: gradually reduce it - name: datarace - name: duplicated-imports - name: early-return diff --git a/internal/boxcli/featureflag/feature.go b/internal/boxcli/featureflag/feature.go index bfeb3fee374..89042cf63a8 100644 --- a/internal/boxcli/featureflag/feature.go +++ b/internal/boxcli/featureflag/feature.go @@ -14,7 +14,6 @@ type feature struct { var features = map[string]*feature{} -// nolint:unparam func disabled(name string) *feature { if features[name] == nil { features[name] = &feature{name: name} @@ -23,7 +22,6 @@ func disabled(name string) *feature { return features[name] } -// nolint:unparam func enabled(name string) *feature { if features[name] == nil { features[name] = &feature{name: name} diff --git a/internal/boxcli/generate/devcontainer_util.go b/internal/boxcli/generate/devcontainer_util.go index 5b54b1f049e..8c9737e5f59 100644 --- a/internal/boxcli/generate/devcontainer_util.go +++ b/internal/boxcli/generate/devcontainer_util.go @@ -33,7 +33,7 @@ type vscode struct { Extensions []string `json:"extensions"` } -// Creates a Dockerfile in path and writes devcontainerDockerfile.tmpl's content into it +// CreateDockerfile creates a Dockerfile in path and writes devcontainerDockerfile.tmpl's content into it func CreateDockerfile(tmplFS embed.FS, path string) error { // create dockerfile file, err := os.Create(filepath.Join(path, "Dockerfile")) diff --git a/internal/fileutil/fileutil.go b/internal/fileutil/fileutil.go index f012b520efe..7aad051fa31 100644 --- a/internal/fileutil/fileutil.go +++ b/internal/fileutil/fileutil.go @@ -38,21 +38,6 @@ func IsFile(path string) bool { return info.Mode().IsRegular() } -// IsSymlink returns true if the path exists *and* it is a symlink. -// -// It does *not* traverse symbolic links, and returns true even if the symlink -// is broken. -// -// This is a convenience function that coerces errors to false. If it cannot -// read the path for any reason (including a permission error) it returns false. -func IsSymlink(path string) bool { - info, err := os.Lstat(path) - if err != nil { - return false - } - return (info.Mode().Type() & os.ModeSymlink) == os.ModeSymlink -} - func Exists(path string) bool { err := TryExists(path) return err == nil diff --git a/internal/impl/devbox.go b/internal/impl/devbox.go index 7abf30c8e27..32ee6db7d65 100644 --- a/internal/impl/devbox.go +++ b/internal/impl/devbox.go @@ -434,21 +434,21 @@ func (d *Devbox) saveCfg() error { } func (d *Devbox) Services() (services.Services, error) { - result := services.Services{} pluginSvcs, err := plugin.GetServices(d.mergedPackages(), d.projectDir) if err != nil { - return result, err + return nil, err } userSvcs := services.FromProcessComposeYaml(d.projectDir) - svcSet, err := lo.Assign(pluginSvcs, userSvcs), nil - + svcSet := lo.Assign(pluginSvcs, userSvcs) keys := make([]string, 0, len(svcSet)) for k := range svcSet { keys = append(keys, k) } slices.Sort(keys) + + result := services.Services{} for _, k := range keys { result[k] = svcSet[k] } diff --git a/internal/impl/shell.go b/internal/impl/shell.go index fa7325426f7..34b1538c421 100644 --- a/internal/impl/shell.go +++ b/internal/impl/shell.go @@ -16,6 +16,7 @@ import ( "github.com/alessio/shellescape" "github.com/pkg/errors" + "go.jetpack.io/devbox/internal/debug" "go.jetpack.io/devbox/internal/nix" "go.jetpack.io/devbox/internal/xdg" @@ -40,12 +41,11 @@ const ( shPosix name = "posix" ) -var ErrNoRecognizableShellFound = errors.New( - "SHELL in undefined, and couldn't find any common shells in PATH") +var ErrNoRecognizableShellFound = errors.New("SHELL in undefined, and couldn't find any common shells in PATH") // TODO consider splitting this struct's functionality so that there is a simpler // `nix.Shell` that can produce a raw nix shell once again. -// + // DevboxShell configures a user's shell to run in Devbox. Its zero value is a // fallback shell that launches a regular Nix shell. type DevboxShell struct { @@ -179,8 +179,7 @@ func WithHooksFilePath(hooksFilePath string) ShellOption { } } -// TODO: Consider removing this once plugins add env vars directly to binaries -// via wrapper scripts. +// TODO: Consider removing this once plugins add env vars directly to binaries via wrapper scripts. func WithEnvVariables(envVariables map[string]string) ShellOption { return func(s *DevboxShell) { s.env = envVariables diff --git a/internal/services/config.go b/internal/services/config.go index 3106fc1e089..e2b109851bc 100644 --- a/internal/services/config.go +++ b/internal/services/config.go @@ -7,28 +7,30 @@ import ( "github.com/f1bonacc1/process-compose/src/types" "github.com/pkg/errors" + "go.jetpack.io/devbox/internal/cuecfg" ) func FromProcessComposeYaml(projectDir string) Services { // TODO need to handle if a filepath is passed in - if processComposeYaml := lookupProcessCompose(projectDir, ""); processComposeYaml != "" { - userSvcs, err := readProcessCompose(processComposeYaml) - if err != nil { - fmt.Fprintf(os.Stderr, "error reading process-compose.yaml: %s, skipping", err) - return nil - } - return userSvcs + processComposeYaml := lookupProcessCompose(projectDir, "") + if processComposeYaml == "" { + return nil + } + userSvcs, err := readProcessCompose(processComposeYaml) + if err != nil { + fmt.Fprintf(os.Stderr, "error reading process-compose.yaml: %s, skipping", err) + return nil } - return Services{} + return userSvcs } func readProcessCompose(path string) (Services, error) { processCompose := &types.Project{} services := Services{} - errors := errors.WithStack(cuecfg.ParseFile(path, processCompose)) - if errors != nil { - return nil, errors + err := errors.WithStack(cuecfg.ParseFile(path, processCompose)) + if err != nil { + return nil, err } for name := range processCompose.Processes { diff --git a/internal/services/status.go b/internal/services/status.go index c7334468bf5..78a164da033 100644 --- a/internal/services/status.go +++ b/internal/services/status.go @@ -12,6 +12,7 @@ import ( "github.com/fsnotify/fsnotify" "github.com/pkg/errors" + "go.jetpack.io/devbox/internal/cloud/envir" ) @@ -44,40 +45,42 @@ func ListenToChanges(ctx context.Context, opts *ListenerOpts) error { }() // Start listening for events. - go func() { - for { - select { - case event, ok := <-watcher.Events: - if !ok { - return - } + go listenToEvents(watcher, opts) - // mutagen sync changes show up as create events - if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) { - status, err := readServiceStatus(event.Name) - if err != nil { - fmt.Fprintf(opts.Writer, "Error reading status file: %s\n", err) - continue - } + // We only want events for the specific host. + return errors.WithStack(watcher.Add(filepath.Join(cloudFilePath(opts.ProjectDir), opts.HostID))) +} - status, saveChanges := opts.UpdateFunc(status) - if saveChanges { - if err := writeServiceStatusFile(event.Name, status); err != nil { - fmt.Fprintf(opts.Writer, "Error updating status file: %s\n", err) - } - } +func listenToEvents(watcher *fsnotify.Watcher, opts *ListenerOpts) { + for { + select { + case event, ok := <-watcher.Events: + if !ok { + return + } + + // mutagen sync changes show up as create events + if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) { + status, err := readServiceStatus(event.Name) + if err != nil { + fmt.Fprintf(opts.Writer, "Error reading status file: %s\n", err) + continue } - case err, ok := <-watcher.Errors: - if !ok { - return + + status, saveChanges := opts.UpdateFunc(status) + if saveChanges { + if err := writeServiceStatusFile(event.Name, status); err != nil { + fmt.Fprintf(opts.Writer, "Error updating status file: %s\n", err) + } } - fmt.Fprintf(opts.Writer, "error: %s\n", err) } + case err, ok := <-watcher.Errors: + if !ok { + return + } + fmt.Fprintf(opts.Writer, "error: %s\n", err) } - }() - - // We only want events for the specific host. - return errors.WithStack(watcher.Add(filepath.Join(cloudFilePath(opts.ProjectDir), opts.HostID))) + } } func cloudFilePath(projectDir string) string {