-
Notifications
You must be signed in to change notification settings - Fork 249
[RFC] [refactor] Consolidate profile update code under syncPackagesToProfile #1529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
1cd1389
to
754575d
Compare
754575d
to
5cd0ec8
Compare
My proposal for the next PR is: In the future, we can also augment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer!
// if mode is install or uninstall, then we need to update the nix-profile | ||
// and lockfile, so we must continue below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this strictly true? for example adding a package that is already in devbox.json. Doesn't feel like a blocker though, I think it's OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm you are correct, its not strictly needed if the same package is being added or removed. We do run it, but its fairly fast (1 second), because its essentially a no-op, but not instant (0 seconds).
internal/impl/packages.go
Outdated
for _, pkg := range packages { | ||
if item.Matches(pkg, d.lockfile) { | ||
itemsToKeep = append(itemsToKeep, item) | ||
continue outer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, can we replace continue outer
with a found
boolean?
for _, item := range profileItems {
found := false
for _, pkg := range packages {
if item.Matches(pkg, d.lockfile) {
itemsToKeep = append(itemsToKeep, item)
found = true
break
}
}
if !found {
extras = append(extras, item)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha yes, lets do that.
f110f09
to
d5748d7
Compare
Summary
This PR refactors code to reduce duplication of logic around nix profile updates.
Specifically:
syncPackagesToProfile
is refactored so that we first prepare profileDir, and installablePackages, and then remove extra packages from profile, and add missing packages to profile. Preparing these variables upfront reduces much code duplication.devbox.Remove
, we now rely onensurePackagesAreInstalled
callingsyncPackagesToProfile
to remove the package from the profile. We can eliminate the extraremovePackagesFromProfile
function.ensurePackagesAreInstalled
, we now always execute it ifmode
isinstall
oruninstall
. We only check the lockfile status forensure
mode.How was it tested?
Did some basic adding and removing of packages