Skip to content
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

Remove unnecessary archive code; fix .tar.xz support #214

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 9 additions & 42 deletions pkg/action/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func extractTar(ctx context.Context, d string, f string) error {
}
defer gzStream.Close()
tr = tar.NewReader(gzStream)
} else if strings.Contains(filename, ".tar.xz") {
}
if strings.Contains(filename, ".tar.xz") {
xzStream, err := xz.NewReader(tf)
if err != nil {
return fmt.Errorf("failed to create xz reader: %w", err)
Expand Down Expand Up @@ -85,19 +86,6 @@ func extractTar(ctx context.Context, d string, f string) error {
return fmt.Errorf("failed to copy file: %w", err)
}

// If the file is an archive, recursively extract it
ext := getExt(target)
if _, ok := archiveMap[ext]; ok {
// determine the file type to choose the right extraction method
extract := extractionMethod(ext)
if extract == nil {
return fmt.Errorf("unsupported archive type: %s", ext)
}
if err := extract(ctx, d, target); err != nil {
return fmt.Errorf("failed to extract nested archive: %w", err)
}
}

if err := f.Close(); err != nil {
return fmt.Errorf("failed to close file: %w", err)
}
Expand Down Expand Up @@ -141,19 +129,6 @@ func extractGzip(ctx context.Context, d string, f string) error {
return fmt.Errorf("failed to copy file: %w", err)
}

// If the file is an archive, recursively extract it
ext := getExt(target)
if _, ok := archiveMap[ext]; ok {
// determine the file type to choose the right extraction method
extract := extractionMethod(ext)
if extract == nil {
return fmt.Errorf("unsupported archive type: %s", ext)
}
if err := extract(ctx, d, target); err != nil {
return fmt.Errorf("failed to extract nested archive: %w", err)
}
}

return nil
}

Expand Down Expand Up @@ -213,18 +188,6 @@ func extractZip(ctx context.Context, d string, f string) error {
return fmt.Errorf("failed to copy file: %w", err)
}

// If the file is an archive, recursively extract it
ext := getExt(name)
if _, ok := archiveMap[ext]; ok {
// determine the file type to choose the right extraction method
extract := extractionMethod(ext)
if extract == nil {
return fmt.Errorf("unsupported archive type: %s", ext)
}
if err := extract(ctx, d, name); err != nil {
return fmt.Errorf("failed to extract nested archive: %w", err)
}
}
open.Close()
create.Close()
}
Expand Down Expand Up @@ -300,8 +263,12 @@ func extractArchiveToTempDir(ctx context.Context, path string) (string, error) {
}

for file := range extractedFiles {
if err := extractNestedArchive(ctx, tmpDir, file, extractedFiles); err != nil {
return "", fmt.Errorf("extract nested archive: %w", err)
ext := getExt(file)
if _, ok := archiveMap[ext]; ok {
fmt.Printf("found a nested archive %s", file)
if err := extractNestedArchive(ctx, tmpDir, file, extractedFiles); err != nil {
return "", fmt.Errorf("extract nested archive: %w", err)
}
}
}

Expand All @@ -314,7 +281,7 @@ func extractionMethod(ext string) func(context.Context, string, string) error {
return extractZip
case ".gz":
return extractGzip
case ".apk", ".gem", ".tar", ".tar.gz", ".tgz":
case ".apk", ".gem", ".tar", ".tar.gz", ".tgz", ".tar.xz":
return extractTar
default:
return nil
Expand Down