Skip to content

Commit 5198328

Browse files
authored
fix(zip): ZIPValidationResult (#22)
Signed-off-by: Lucian Maly <lucian@redhat.com>
1 parent aa7672a commit 5198328

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

internal/checksum/display.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ func DisplayZIPResult(result *ZIPValidationResult, opts Options) bool {
326326
fmt.Fprintf(display.output, "\n%s\n", magenta("Validating ZIP:"))
327327
fmt.Fprintf(display.output, " %-13s %s\n", label("ZIP file:"), result.ZIPFile.Path)
328328
fmt.Fprintf(display.output, " %-13s %d\n", label("Files in archive:"), result.TotalEntries)
329+
330+
// If ZIP file couldn't be parsed, show the error
331+
if result.TotalEntries == 0 && len(result.Errors) > 0 {
332+
fmt.Fprintf(display.output, " %-13s %s\n", label("Error:"), errorColor(result.Errors[0].Error()))
333+
}
329334
fmt.Fprintln(display.output)
330335

331336
// Show individual results if verbose

internal/checksum/zip.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ type ZIPEntry struct {
1818

1919
// ZIPResult represents the result of validating a single ZIP entry
2020
type ZIPResult struct {
21-
Entry ZIPEntry
22-
Valid bool
23-
Error error
21+
Entry ZIPEntry
22+
Valid bool
23+
Error error
2424
}
2525

2626
// ZIPFile represents a ZIP file being validated
@@ -31,12 +31,12 @@ type ZIPFile struct {
3131

3232
// ZIPValidationResult represents the overall result of ZIP validation
3333
type ZIPValidationResult struct {
34-
ZIPFile ZIPFile
35-
Results []ZIPResult
36-
TotalEntries int
37-
ValidEntries int
34+
ZIPFile ZIPFile
35+
Results []ZIPResult
36+
TotalEntries int
37+
ValidEntries int
3838
InvalidEntries int
39-
Errors []error
39+
Errors []error
4040
}
4141

4242
// FindZIPFiles finds all ZIP files in the given directory (case insensitive)
@@ -284,7 +284,21 @@ func validateSingleZIP(zipPath string, opts Options) (bool, error) {
284284
// Parse ZIP file
285285
zip, err := ParseZIPFile(zipPath)
286286
if err != nil {
287-
return false, fmt.Errorf("failed to parse ZIP file %s: %w", zipPath, err)
287+
// Create a result indicating the ZIP file is invalid/corrupted
288+
result := &ZIPValidationResult{
289+
ZIPFile: ZIPFile{
290+
Path: zipPath,
291+
Entries: []ZIPEntry{},
292+
},
293+
Results: []ZIPResult{},
294+
TotalEntries: 0,
295+
ValidEntries: 0,
296+
InvalidEntries: 1, // Mark as invalid since we couldn't parse it
297+
Errors: []error{err},
298+
}
299+
// Display results and return validation status
300+
failed := DisplayZIPResult(result, opts)
301+
return failed, nil
288302
}
289303

290304
// Validate ZIP

0 commit comments

Comments
 (0)