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

Allow --format=ustar option for ptar #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johannessen
Copy link

CPAN distributions should use the standard tar format, “ustar”. However, many modern tar utilties create archives in the extended “pax” format instead, which prevents installing affected dists on some systems. Modules like ExtUtils::MakeMaker have been struggling a bit with this problem.

There is a proposal to have ExtUtils::MakeMaker use Archive::Tar’s ptar by default, instead of system tar:
Perl-Toolchain-Gang/ExtUtils-MakeMaker#349

Meanwhile, some CPAN dists have worked around the problem by adding the --format=ustar option to their ExtUtils::MakeMaker TARFLAGS. Unfortunately, that option is currently not accepted by ptar, so changing EU:MM to use ptar by default would break those workarounds.

This PR proposes to allow ptar to accept a --format=ustar option. If this option is given, ptar silently ignores it, because Archive::Tar always uses the “ustar” format anyway.

@johannessen
Copy link
Author

I’ve considered two edge cases here:

  • GNU tar allows replacing the equals sign with a space, --format ustar. That variant is uncommon for CPAN dists. (The only dist using this that I could find with grep.metacpan.org is Number-Phone.)

  • Creating archives with file names exactly matching a valid option is possible by using -- on the command line, separating options from other arguments. Using that to add a file named literally --format=ustar to an archive is uncommon, but legal.

This proposed change handles both of these cases. I think doing so makes sense as a matter of principle. But if you should feel there is no need for that, this PR could be simplified to just a single line:

@ARGV = grep !/^--format=ustar$/, @ARGV;

@choroba
Copy link

choroba commented Jun 19, 2024

I love it!

Shouldn't there be a test for --format ustar, too?

GNU tar allows replacing the equals sign in long options with a space (--format ustar). That variant is also accepted by this change.

ptar allows creating archives including a file named literally "--format=ustar" by using "--" to separate options from other command line arguments. That way to use ptar is not affected by this change.
@johannessen
Copy link
Author

Good idea, thanks. PR updated.

@Leont
Copy link

Leont commented Jun 19, 2024

I suspect that switching to Getopt::Long so the option can be parsed there is the more maintainable solution.

@johannessen
Copy link
Author

I agree that converting from Getopt::Std to Getopt::Long would improve readability. I, for one, fail to understand Getopt::Std’s syntax.

But that’s kinda a different change. This change is about increasing CLI compatibility with GNU tar.

@Leont
Copy link

Leont commented Jun 23, 2024

But that’s kinda a different change. This change is about increasing CLI compatibility with GNU tar.

It's a different change, but it would make help by being the more maintainable solution. Once you have Getopt::Long you could not only add a format flag as a one-liner, you could also trivially give a sensible warning if someone does --format=pax or some such.

@johannessen
Copy link
Author

I agree completely.

Sorry for not responding earlier, and for not being clear before. The point I was trying to make is that the change discussed here is in effect a feature update, while the change you’re proposing is a refactoring. I think the two shouldn’t be conflated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants