Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
fix(action): use Archive::Tar module instead of tar command (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
garnier-quentin authored and chgautier committed Dec 10, 2021
1 parent b0ac91b commit fbc8c5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
29 changes: 10 additions & 19 deletions gorgone/modules/core/action/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ use File::Copy;
use File::Path qw(make_path);
use MIME::Base64;
use Digest::MD5::File qw(file_md5_hex);
use Archive::Tar;
use Fcntl;

$Archive::Tar::SAME_PERMISSIONS = 1;
$Archive::Tar::WARN = 0;
$Digest::MD5::File::NOFATALS = 1;
my %handlers = (TERM => {}, HUP => {});
my ($connector);
Expand Down Expand Up @@ -329,30 +332,18 @@ sub action_processcopy {
if (! -d $options{data}->{content}->{destination}) {
make_path($options{data}->{content}->{destination});
}
my ($error, $stdout, $exit_code) = gorgone::standard::misc::backtick(
command => "tar --no-overwrite-dir -zxf $cache_file -C '" . $options{data}->{content}->{destination} . "' .",
timeout => (defined($options{timeout})) ? $options{timeout} : 10,
wait_exit => 1,
redirect_stderr => 1,
);
if ($error <= -1000) {
$self->send_log(
code => GORGONE_ACTION_FINISH_KO,
token => $options{token},
logging => $options{data}->{logging},
data => { message => "untar failed: $stdout" }
);
$self->{logger}->writeLogError('[action] Copy processing - Untar failed: ' . $stdout);
return -1;
}
if ($exit_code != 0) {

my $tar = Archive::Tar->new();
$tar->setcwd($options{data}->{content}->{destination});
unless ($tar->read($cache_file, undef, { extract => 1 })) {
my $tar_error = $tar->error();
$self->send_log(
code => GORGONE_ACTION_FINISH_KO,
token => $options{token},
logging => $options{data}->{logging},
data => { message => "untar failed ($exit_code): $stdout" }
data => { message => "untar failed: $tar_error" }
);
$self->{logger}->writeLogError('[action] Copy processing - Untar failed: ' . $stdout);
$self->{logger}->writeLogError("[action] Copy processing - Untar failed: $tar_error");
return -1;
}
} elsif ($options{data}->{content}->{type} eq 'regular') {
Expand Down
1 change: 1 addition & 0 deletions packaging/centreon-gorgone.spectemplate
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: bzip2
Requires: perl-Libssh-Session >= 0.8
Requires: perl-CryptX
Requires: perl(Archive::Tar)
Requires: perl(Schedule::Cron)
Requires: perl(ZMQ::LibZMQ4)
Requires: perl(ZMQ::Constants)
Expand Down

0 comments on commit fbc8c5b

Please sign in to comment.