Permalink
Browse files

Item13929: Handle BSD tar utility

Fix provided by VadimBelman
  • Loading branch information...
gac410 committed Nov 10, 2016
1 parent 246450c commit 5c5d515630e234b37e1c130b0b5c321556a1db4e
Showing with 43 additions and 3 deletions.
  1. +43 −3 core/lib/Foswiki/Configure/FileUtil.pm
@@ -698,6 +698,35 @@ sub listDir {
return @names;
}
sub _getTarFamily {
my ($tarCmd) = @_;
`$tarCmd --version` =~ /(bsd|gnu)/i;
return lc $1;
}
sub _getTar {
my $tarCmd = 'tar';
my $tarFamily = _getTarFamily($tarCmd);
if ( $tarFamily eq 'bsd' ) {
# Trying to find gnutar in order to keep as much compatibility with
# linux as we can.
my $gnutar = `which gnutar`;
if ( $? == 0 && $gnutar ) {
chomp $gnutar;
if ( _getTarFamily($gnutar) eq 'gnu' ) {
$tarCmd = $gnutar;
$tarFamily = 'gnu';
}
}
}
return ( $tarCmd, $tarFamily );
}
=begin TML
---++ StaticMethod createArchive($name, $dir, $delete )
@@ -727,9 +756,20 @@ sub createArchive {
chdir("$dir/$name");
if ( !defined $test || ( defined $test && $test eq 'tar' ) ) {
$results .= `tar -czvf "../$name.tgz" .`;
my ( $tarCmd, $tarFamily ) = _getTar();
my $redirect = '';
if ( $tarFamily eq 'bsd' ) {
# BSD tar sends listing to STDERR while create an archive.
$redirect = '2>&1';
}
$results = `$tarCmd -czvf "../$name.tgz" . $redirect`;
if ( $results && !$@ ) {
if ( $? != 0 ) {
$results = '';
}
else {
$file = "$dir/$name.tgz";
}
}
@@ -740,7 +780,7 @@ sub createArchive {
if ( !defined $test || ( defined $test && $test eq 'zip' ) ) {
$results .= `zip -r "../$name.zip" .`;
if ( $results && !$@ ) {
if ( $results && !$? ) {
$file = "$dir/$name.zip";
}
}

0 comments on commit 5c5d515

Please sign in to comment.