| 1 | package VCI::VCS::Cvs; | ||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | our $VERSION = '0.7.1'; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use MooseX::Method; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | extends 'VCI'; | ||||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Cwd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use IPC::Cmd; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw(tainted); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use VCI::Util qw(taint_fail detaint); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | has 'x_cvsps' => (is => 'ro', isa => 'Str', lazy_build => 1); | ||||||||||
| 15 | has 'x_cvs' => (is => 'ro', isa => 'Str', lazy_build => 1); | ||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
| |||||||||||
| 18 | 0 | my $self = shift; | |||||||||
| 19 | taint_fail("The x_cvs argument '$self->{x_cvs}' is tainted") | ||||||||||
| 20 | 0 | ▶ | if tainted($self->{x_cvs}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | taint_fail("The x_cvsps argument '$self->{x_cvsps}' is tainted") | ||||||||||
| 22 | 0 | ▶ | if tainted($self->{x_cvsps}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 2 | ▶ | use constant revisions_are_global => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 2 | ▶ | use constant revisions_are_universal => 0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | sub missing_requirements { | ||||||||||
| 29 | my @need; | ||||||||||
| 30 | foreach my $bin qw(cvs cvsps) { | ||||||||||
| 31 | push(@need, $bin) if !IPC::Cmd::can_run($bin); | ||||||||||
| 32 | } | ||||||||||
| 33 | return @need; | ||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | sub _build_x_cvsps { | ||||||||||
| 37 | my $cmd = IPC::Cmd::can_run('cvsps') | ||||||||||
| 38 | || confess('Could not find "cvsps" in your path'); | ||||||||||
| 39 | taint_fail("We found '$cmd' for cvsps, but that string is tainted." | ||||||||||
| 40 | . ' This probably means $ENV{PATH} is tainted') | ||||||||||
| 41 | if tainted($cmd); | ||||||||||
| 42 | return $cmd; | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub _build_x_cvs { | ||||||||||
| 46 | my $cmd = IPC::Cmd::can_run('cvs') | ||||||||||
| 47 | || confess('Could not find "cvs" in your path'); | ||||||||||
| 48 | taint_fail("We found '$cmd' for cvs, but that string is tainted." | ||||||||||
| 49 | . ' This probably means $ENV{PATH} is tainted') | ||||||||||
| 50 | if tainted($cmd); | ||||||||||
| 51 | return $cmd; | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | method 'x_do' => named ( | ||||||||||
| 55 | args => { isa => 'ArrayRef', required => 1 }, | ||||||||||
| 56 | fromdir => { isa => 'Str', default => '.' }, | ||||||||||
| 57 | ) => sub { | ||||||||||
| 58 | my ($self, $params) = @_; | ||||||||||
| 59 | my $fromdir = $params->{fromdir}; | ||||||||||
| 60 | my $args = $params->{args}; | ||||||||||
| 61 | |||||||||||
| 62 | my $full_command = $self->x_cvs . ' -f ' . join(' ', @$args); | ||||||||||
| 63 | if ($self->debug) { | ||||||||||
| 64 | print STDERR "Command: $full_command\n", | ||||||||||
| 65 | " From: $fromdir\n"; | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | my $old_cwd = cwd(); | ||||||||||
| 69 | chdir $fromdir or confess("Failed to chdir to $fromdir: $!"); | ||||||||||
| 70 | |||||||||||
| 71 | my ($success, $error_msg, $all, $stdout, $stderr) = | ||||||||||
| 72 | IPC::Cmd::run(command => [$self->x_cvs, '-f', @$args]); | ||||||||||
| 73 | |||||||||||
| 74 | my $error_code = 0; | ||||||||||
| 75 | if (defined $error_msg) { | ||||||||||
| 76 | if ($error_msg =~ /exited with value (\d+)/) { | ||||||||||
| 77 | $error_code = $1; | ||||||||||
| 78 | } | ||||||||||
| 79 | else { | ||||||||||
| 80 | $error_code = -1; | ||||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | # We are forced to trust this directory, and we don't do | ||||||||||
| 85 | # anything dangerous with it, only chdir (which we can't do while | ||||||||||
| 86 | # it's tainted). | ||||||||||
| 87 | detaint($old_cwd); | ||||||||||
| 88 | chdir $old_cwd or confess("Failed to chdir back to $old_cwd: $!"); | ||||||||||
| 89 | |||||||||||
| 90 | # "cvs diff" returns 256 always, it seems. | ||||||||||
| 91 | if (!$success && !(grep($_ eq 'diff', @$args) && $error_code == 256)) { | ||||||||||
| 92 | my $err_string = join('', @$stderr); | ||||||||||
| 93 | chomp($err_string); | ||||||||||
| 94 | confess("$full_command failed: $err_string"); | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | my $output = join('', @$all); | ||||||||||
| 98 | if ($self->debug) { | ||||||||||
| 99 | print STDERR "Error Message: $error_msg\n" if $error_msg; | ||||||||||
| 100 | (print STDERR "Results: $output\n") if $self->debug > 1; | ||||||||||
| 101 | } | ||||||||||
| 102 | return $output; | ||||||||||
| 103 | }; | ||||||||||
| 104 | |||||||||||
| 105 | __PACKAGE__->meta->make_immutable; | ||||||||||
| 106 | |||||||||||
| 107 | 1; | ||||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||