mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Fix Reinstall, version-pinned, error propagation, and DryRun bugs in Install/Remove pre-filter
Co-authored-by: taigrr <8261498+taigrr@users.noreply.github.com>
This commit is contained in:
@@ -78,10 +78,18 @@ func runAptGet(ctx context.Context, command string, pkgs []snack.Target, opts ..
|
||||
}
|
||||
|
||||
func install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (snack.InstallResult, error) {
|
||||
o := snack.ApplyOptions(opts...)
|
||||
var toInstall []snack.Target
|
||||
var unchanged []string
|
||||
for _, t := range pkgs {
|
||||
ok, _ := isInstalled(ctx, t.Name)
|
||||
if o.Reinstall || t.Version != "" || o.DryRun {
|
||||
toInstall = append(toInstall, t)
|
||||
continue
|
||||
}
|
||||
ok, err := isInstalled(ctx, t.Name)
|
||||
if err != nil {
|
||||
return snack.InstallResult{}, err
|
||||
}
|
||||
if ok {
|
||||
unchanged = append(unchanged, t.Name)
|
||||
} else {
|
||||
@@ -102,10 +110,18 @@ func install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (sn
|
||||
}
|
||||
|
||||
func remove(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (snack.RemoveResult, error) {
|
||||
o := snack.ApplyOptions(opts...)
|
||||
var toRemove []snack.Target
|
||||
var unchanged []string
|
||||
for _, t := range pkgs {
|
||||
ok, _ := isInstalled(ctx, t.Name)
|
||||
if o.DryRun {
|
||||
toRemove = append(toRemove, t)
|
||||
continue
|
||||
}
|
||||
ok, err := isInstalled(ctx, t.Name)
|
||||
if err != nil {
|
||||
return snack.RemoveResult{}, err
|
||||
}
|
||||
if !ok {
|
||||
unchanged = append(unchanged, t.Name)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user