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

add support to TarArchiver for more common compression suffixes #8369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

toffaletti
Copy link

@toffaletti toffaletti commented Mar 13, 2025

  • include more suffixes for: gzip, bzip2, lzma, xz

Motivation:

Add support for compression algorithms that can achieve higher compression ratios than gzip.
Support another common extension for gzip as well.

Modifications:

I modified the list of supported extensions for the TarArchiver.

I researched various manpages to see what was commonly supported.

  • The GNU tar manpage has the most extensive list of suffixes.
  • FreeBSD tar supports most of what GNU tar does in terms of compression algorithms.
  • OpenBSD tar doesn't support the a flag used for auto-compress which TarArchiver.compress uses ref. It also doesn't seem to have anything beyond gzip and bzip2 (no lzma or xz).
  • NetBSD tar has gzip, bzip2, lzma, xz
  • Windows tar.exe seems to be a port of BSD tar similar in support to NetBSD.
  • macOS tar is an older FreeBSD tar, similar support to NetBSD.

Result:

More compression algorithms will be supported.

- include more suffixes for: gzip, bzip2, lzma, xz
@toffaletti
Copy link
Author

I wasn't sure about adding test files for all these extensions?

@@ -16,7 +16,14 @@ import struct TSCBasic.FileSystemError

/// An `Archiver` that handles Tar archives using the command-line `tar` tool.
public struct TarArchiver: Archiver {
public let supportedExtensions: Set<String> = ["tar", "tar.gz"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't clear to me whether "tar.gz" is really needed or if "gz" is good enough here? The tar commands don't seem to care:

 tar tzf test.gz | head
6.0.3-RELEASE_rhel_ubi9_x86_64.artifactbundle/
6.0.3-RELEASE_rhel_ubi9_x86_64.artifactbundle/6.0.3-RELEASE_rhel_ubi9_x86_64/
6.0.3-RELEASE_rhel_ubi9_x86_64.artifactbundle/info.json
6.0.3-RELEASE_rhel_ubi9_x86_64.artifactbundle/6.0.3-RELEASE_rhel_ubi9_x86_64/x86_64-unknown-linux-gnu/

@dschaefer2
Copy link
Member

I wasn't sure about adding test files for all these extensions?

Tests would be extremely helpful. It's hard to know whether these things work or will stay working without them.

@MaxDesiatov MaxDesiatov added the needs tests This change needs test coverage label Mar 17, 2025
@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Mar 17, 2025

Another thing to keep in mind that not all of these formats are supported by tar on all platforms that SwiftPM supports. We need to make sure that in case of unsupported formats appropriate diagnostic message is emitted to the user and that this support is detected correctly on a given platform.

@toffaletti
Copy link
Author

Another thing to keep in mind that not all of these formats are supported by tar on all platforms that SwiftPM supports. We need to make sure that in case of unsupported formats appropriate diagnostic message is emitted to the user and that this support is detected correctly on a given platform.

Is there a canonical list of supported platforms and their versions?

@MaxDesiatov
Copy link
Contributor

Is there a canonical list of supported platforms and their versions?

Yes, it's available at https://swift.org/install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests This change needs test coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants