mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Merge remote-tracking branch 'origin/copilot/add-isheld-method-to-holder-interface' into cd/integration-copilot-prs
This commit is contained in:
@@ -124,6 +124,11 @@ func (a *Apt) ListHeld(ctx context.Context) ([]snack.Package, error) {
|
|||||||
return listHeld(ctx)
|
return listHeld(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsHeld reports whether a specific package is currently held.
|
||||||
|
func (a *Apt) IsHeld(ctx context.Context, pkg string) (bool, error) {
|
||||||
|
return isHeld(ctx, pkg)
|
||||||
|
}
|
||||||
|
|
||||||
// Autoremove removes packages no longer required as dependencies.
|
// Autoremove removes packages no longer required as dependencies.
|
||||||
func (a *Apt) Autoremove(ctx context.Context, opts ...snack.Option) error {
|
func (a *Apt) Autoremove(ctx context.Context, opts ...snack.Option) error {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
|
|||||||
@@ -230,6 +230,16 @@ func TestIntegration_Apt(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("IsHeld", func(t *testing.T) {
|
||||||
|
held, err := h.IsHeld(ctx, "tree")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.True(t, held, "tree should be held")
|
||||||
|
|
||||||
|
notHeld, err := h.IsHeld(ctx, "curl")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.False(t, notHeld, "curl should not be held")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("ListHeld", func(t *testing.T) {
|
t.Run("ListHeld", func(t *testing.T) {
|
||||||
held, err := h.ListHeld(ctx)
|
held, err := h.ListHeld(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -159,6 +159,15 @@ func listHeld(ctx context.Context) ([]snack.Package, error) {
|
|||||||
return pkgs, nil
|
return pkgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHeld(ctx context.Context, pkg string) (bool, error) {
|
||||||
|
cmd := exec.CommandContext(ctx, "apt-mark", "showhold", pkg)
|
||||||
|
out, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("apt-mark showhold %s: %w", pkg, err)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(string(out)) == pkg, nil
|
||||||
|
}
|
||||||
|
|
||||||
// --- Cleaner ---
|
// --- Cleaner ---
|
||||||
|
|
||||||
func autoremove(ctx context.Context, opts ...snack.Option) error {
|
func autoremove(ctx context.Context, opts ...snack.Option) error {
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ func listHeld(_ context.Context) ([]snack.Package, error) {
|
|||||||
return nil, snack.ErrUnsupportedPlatform
|
return nil, snack.ErrUnsupportedPlatform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHeld(_ context.Context, _ string) (bool, error) {
|
||||||
|
return false, snack.ErrUnsupportedPlatform
|
||||||
|
}
|
||||||
|
|
||||||
func autoremove(_ context.Context, _ ...snack.Option) error {
|
func autoremove(_ context.Context, _ ...snack.Option) error {
|
||||||
return snack.ErrUnsupportedPlatform
|
return snack.ErrUnsupportedPlatform
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ func (d *DNF) ListHeld(ctx context.Context) ([]snack.Package, error) {
|
|||||||
return listHeld(ctx, d.v5)
|
return listHeld(ctx, d.v5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsHeld reports whether a specific package is currently held.
|
||||||
|
func (d *DNF) IsHeld(ctx context.Context, pkg string) (bool, error) {
|
||||||
|
return isHeld(ctx, pkg, d.v5)
|
||||||
|
}
|
||||||
|
|
||||||
// Autoremove removes orphaned packages.
|
// Autoremove removes orphaned packages.
|
||||||
func (d *DNF) Autoremove(ctx context.Context, opts ...snack.Option) error {
|
func (d *DNF) Autoremove(ctx context.Context, opts ...snack.Option) error {
|
||||||
d.Lock()
|
d.Lock()
|
||||||
|
|||||||
@@ -113,6 +113,19 @@ func listHeld(ctx context.Context, v5 bool) ([]snack.Package, error) {
|
|||||||
return parseVersionLock(out), nil
|
return parseVersionLock(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHeld(ctx context.Context, pkg string, v5 bool) (bool, error) {
|
||||||
|
held, err := listHeld(ctx, v5)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, p := range held {
|
||||||
|
if p.Name == pkg {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func autoremove(ctx context.Context, opts ...snack.Option) error {
|
func autoremove(ctx context.Context, opts ...snack.Option) error {
|
||||||
o := snack.ApplyOptions(opts...)
|
o := snack.ApplyOptions(opts...)
|
||||||
_, err := run(ctx, []string{"autoremove", "-y"}, o)
|
_, err := run(ctx, []string{"autoremove", "-y"}, o)
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ func listHeld(_ context.Context, _ bool) ([]snack.Package, error) {
|
|||||||
return nil, snack.ErrUnsupportedPlatform
|
return nil, snack.ErrUnsupportedPlatform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHeld(_ context.Context, _ string, _ bool) (bool, error) {
|
||||||
|
return false, snack.ErrUnsupportedPlatform
|
||||||
|
}
|
||||||
|
|
||||||
func autoremove(_ context.Context, _ ...snack.Option) error {
|
func autoremove(_ context.Context, _ ...snack.Option) error {
|
||||||
return snack.ErrUnsupportedPlatform
|
return snack.ErrUnsupportedPlatform
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,6 +225,16 @@ func TestIntegration_DNF(t *testing.T) {
|
|||||||
t.Skipf("versionlock plugin not available: %v", err)
|
t.Skipf("versionlock plugin not available: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("IsHeld", func(t *testing.T) {
|
||||||
|
held, err := h.IsHeld(ctx, "tree")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.True(t, held, "tree should be held")
|
||||||
|
|
||||||
|
notHeld, err := h.IsHeld(ctx, "curl")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.False(t, notHeld, "curl should not be held")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("ListHeld", func(t *testing.T) {
|
t.Run("ListHeld", func(t *testing.T) {
|
||||||
held, err := h.ListHeld(ctx)
|
held, err := h.ListHeld(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
3
snack.go
3
snack.go
@@ -125,6 +125,9 @@ type Holder interface {
|
|||||||
|
|
||||||
// ListHeld returns all currently held/pinned packages.
|
// ListHeld returns all currently held/pinned packages.
|
||||||
ListHeld(ctx context.Context) ([]Package, error)
|
ListHeld(ctx context.Context) ([]Package, error)
|
||||||
|
|
||||||
|
// IsHeld reports whether a specific package is currently held/pinned.
|
||||||
|
IsHeld(ctx context.Context, pkg string) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleaner provides orphan/cache cleanup operations.
|
// Cleaner provides orphan/cache cleanup operations.
|
||||||
|
|||||||
Reference in New Issue
Block a user