From: Graham Knop Date: Tue, 14 Apr 2020 08:40:25 +0000 (+0200) Subject: set uid and gid when using bsd tar X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c34106970628efc3f1b176bcbffe99e6186fa825;p=p5sagit%2FDistar.git set uid and gid when using bsd tar It's possible to set the user and group when using bsd tar, but the options are different from GNU tar. Use these options, and simplify the code that handles this. --- diff --git a/helpers/verify-tarball b/helpers/verify-tarball index eb62f8b..3a88e3e 100755 --- a/helpers/verify-tarball +++ b/helpers/verify-tarball @@ -56,6 +56,10 @@ if (@extra) { if (@missing) { $message .= "$tarball is missing files:\n" . join '', map " $_\n", @missing; } -die $message - if $message; +if ($message) { + die $message . <<'END_MESSAGE'; + +This may happen if the file attributes are not compatible with the ustar format. +END_MESSAGE +} exit 0; diff --git a/lib/Distar.pm b/lib/Distar.pm index 4963457..3ded7cd 100644 --- a/lib/Distar.pm +++ b/lib/Distar.pm @@ -135,57 +135,22 @@ sub write_manifest_skip { sub init_dist { my $self = shift; - my $pre_tar = $self->{TAR}; my $out = $self->SUPER::init_dist(@_); my $dn = File::Spec->devnull; my $tar = $self->{TAR}; - my $gtar; - my $set_user; - for my $maybe_tar ($tar, qw(gtar gnutar)) { - my $version = `$maybe_tar --version 2>$dn`; - if ($version =~ /GNU tar/) { - $tar = $maybe_tar; - $gtar = 1; - last; - } - } + my $tarflags = $self->{TARFLAGS}; if (my ($flags) = $tarflags =~ /^-?([cvhlLf]+)$/) { if ($flags =~ s/c// && $flags =~ s/f//) { $tarflags = '--format=ustar -c'.$flags.'f'; - if ($gtar) { - $tarflags = '--owner=0 --group=0 '.$tarflags; - $set_user = 1; - } - } - } - - if (!$set_user) { - my $warn = ''; - if ($> >= 2**21) { - $warn .= "uid ($>)"; - } - if ($) >= 2**21) { - $warn .= ($warn ? ' and ' : '').'gid('.(0+$)).')'; - } - if ($warn) { - warn "Current $warn too large to create portable dist archives! Max is ".(2**21-1).".\n" - ."Dist creation will most likely fail. Install GNU tar and re-run Makefile.PL to fix this issue.\n"; - my @try; - my $brew = `which brew 2>$dn`; - chomp $brew; - if (-x $brew) { - push @try, 'brew install gnu-tar'; - } - my $ports = `which ports 2>$dn`; - chomp $ports; - if (-x $ports) { - push @try, 'sudo ports install gnutar'; - } - if (@try) { - warn "Try" . (@try > 1 ? ' one of' : '') . ":\n" - . join '', map " $_\n", @try; + my $me = __FILE__; + for my $options ('--owner=0 --group=0', '--uid=0 --gid=0') { + my $try = `$tar -c $options "$me" 2>$dn`; + if (length $try) { + $tarflags = "$options $tarflags"; + last; + } } } }