File Coverage

perllib/Arch/Tarball.pm
Criterion Covered Total %
statement 12 45 26.6
branch 0 14 0.0
condition 0 20 0.0
subroutine 4 8 50.0
pod 4 4 100.0
total 20 91 21.9


line stmt bran cond sub pod time code
1             # Arch Perl library, Copyright (C) 2004 Mikhael Goikhman
2             #
3             # This program is free software; you can redistribute it and/or modify
4             # it under the terms of the GNU General Public License as published by
5             # the Free Software Foundation; either version 2 of the License, or
6             # (at your option) any later version.
7             #
8             # This program is distributed in the hope that it will be useful,
9             # but WITHOUT ANY WARRANTY; without even the implied warranty of
10             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11             # GNU General Public License for more details.
12             #
13             # You should have received a copy of the GNU General Public License
14             # along with this program; if not, write to the Free Software
15             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16              
17 3     3   81 use 5.005;
  3         12  
  3         133  
18 3     3   21 use strict;
  3         8  
  3         162  
19              
20             package Arch::Tarball;
21              
22 3     3   16 use Arch::Util qw(run_cmd run_pipe_from copy_dir);
  3         7  
  3         208  
23 3     3   16 use Arch::TempFiles qw(temp_dir);
  3         5  
  3         1585  
24              
25             sub new ($%) {
26 0     0 1   my $class = shift;
27 0           my %init = @_;
28              
29 0   0       my $self = {
30             tar => $init{tar} || "tar",
31             file => $init{file},
32             };
33              
34 0           bless $self, $class;
35 0           return $self;
36             }
37              
38             sub create ($%) {
39 0     0 1   my $self = shift;
40 0           my %args = @_;
41 0           my $dir = $args{dir};
42 0 0         die "Arch::Tarball::create: no dir given\n"
43             unless $dir;
44 0 0 0       die "Arch::Tarball::create: bad dir ($dir)\n"
45             unless -d $dir && $dir =~ s!^(.+)/(.+)$!$1!;
46 0           my $base_name = $2;
47 0           my $needed_base_name = $args{base_name};
48 0 0 0       die "Arch::Tarball::create: bad base_name ($needed_base_name)\n"
49             if $needed_base_name && $needed_base_name =~ m!/!;
50 0           my $do_pipe = $args{pipe};
51 0 0         die "Arch::Tarball::create: non-pipe is not implemented yet\n"
52             unless $do_pipe;
53              
54 0 0 0       if ($needed_base_name && $needed_base_name ne $base_name) {
55 0           my $temp_dir = temp_dir("arch-tarball");
56 0           copy_dir("$dir/$base_name", "$temp_dir/$needed_base_name");
57 0           $base_name = $needed_base_name;
58 0           $dir = $temp_dir;
59             }
60              
61 0           my @tar_args = ($self->{tar}, "czf", "-", "-C", $dir, $base_name);
62 0           my $tar_pipe = run_pipe_from(@tar_args);
63 0           return $tar_pipe;
64             }
65              
66             sub extract ($%) {
67 0     0 1   my $self = shift;
68 0           my %args = @_;
69              
70 0 0 0       my $file = $args{file} || $self->{file}
71             or die "Arch::Tarball::extract: No file given in constructor\n";
72 0   0       my $dir = $args{dir} || temp_dir("arch-tarball");
73 0 0 0       die "Arch::Tarball::extract: unexisting dir ($dir)\n"
74             if $args{dir} && !-d $dir;
75              
76 0           run_cmd($self->{tar}, "xz", "-C", $dir, "-f", $file);
77              
78 0           return $dir;
79             }
80              
81             sub list ($%) {
82 0     0 1   my $self = shift;
83 0           my %args = @_;
84 0           die "Not implemented yet";
85             }
86              
87             1;
88              
89             __END__