mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
fix: improve correctness and safety
Pass 2 (Correctness & Safety): - Separate stdout/stderr in apk list and search to prevent error messages from contaminating parsed output - All providers verified: mutex on mutating ops, CommandContext everywhere, proper error wrapping, nil-safe parseInfo functions
This commit is contained in:
@@ -96,18 +96,22 @@ func update(ctx context.Context) error {
|
||||
|
||||
func list(ctx context.Context) ([]snack.Package, error) {
|
||||
cmd := exec.CommandContext(ctx, "apk", "list", "--installed")
|
||||
out, err := cmd.CombinedOutput()
|
||||
var stderr strings.Builder
|
||||
cmd.Stderr = &stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("apk list: %w", err)
|
||||
return nil, fmt.Errorf("apk list: %s: %w", strings.TrimSpace(stderr.String()), err)
|
||||
}
|
||||
return parseListInstalled(string(out)), nil
|
||||
}
|
||||
|
||||
func search(ctx context.Context, query string) ([]snack.Package, error) {
|
||||
cmd := exec.CommandContext(ctx, "apk", "search", "-v", query)
|
||||
out, err := cmd.CombinedOutput()
|
||||
var stderr strings.Builder
|
||||
cmd.Stderr = &stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("apk search: %w", err)
|
||||
return nil, fmt.Errorf("apk search: %s: %w", strings.TrimSpace(stderr.String()), err)
|
||||
}
|
||||
results := parseSearch(string(out))
|
||||
if len(results) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user