Skip to content

Conversation

mikeland73
Copy link
Contributor

Summary

This allows adding and removing runx binaries inside a devbox environment without having to shellenv again.

How was it tested?

devbox shell
which envsec
devbox add runx:jetpack-io/envsec
which envsec
devbox rm runx:jetpack-io/envsec
which envsec

@mikeland73 mikeland73 requested review from gcurtis and savil October 9, 2023 19:59
Copy link
Collaborator

@gcurtis gcurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is okay for internal use, but we should figure out how to handle package conflicts if we ever want to release it more generally.

if err := os.RemoveAll(runxBinPath); err != nil {
return "", err
}
if err := fileutil.EnsureDirExists(runxBinPath, 0o755, false); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as os.MkdirAll.

paths = append(paths, p...)
for _, path := range paths {
// create symlink to all files in p
files, err := os.ReadDir(path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this symlink all files in the archive, including non-binaries? I'm wondering if this will create a bunch of conflicts. For example, if multiple packages have a README in them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it will, but mostly for files we don't care about. We can fix this later on. (Requires priorities similar to nix)

for _, file := range files {
src := filepath.Join(path, file.Name())
dst := filepath.Join(runxBinPath, file.Name())
if err := os.Symlink(src, dst); err != nil && errors.Is(err, os.ErrExist) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ignore other errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this should be !errors.Is(err, os.ErrExist)

Specifically I want to ignore already exist errors for the case of conflicts and race conditions.

if err := fileutil.EnsureDirExists(runxBinPath, 0o755, false); err != nil {
return "", err
}
packages := lo.Filter(d.InstallablePackages(), devpkg.IsRunX)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing devpkg.IsRunX in the loop would avoid cloning the slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change. Though slice is just a pointer slice on stack, I would favor readability over avoiding the opperation.

@mikeland73
Copy link
Contributor Author

I think this is okay for internal use, but we should figure out how to handle package conflicts if we ever want to release it more generally.

The conflicts for sure are not a great experience, but I actually think this is almost ready for release and would not mind releasing with that issue. The main issue I'm not sure about is the runx syntax in devbox.json

@mikeland73 mikeland73 merged commit 8f1f0dc into main Oct 10, 2023
@mikeland73 mikeland73 deleted the landau/runx-single-path branch October 10, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants