Dpkg/Source/Package/V3/Native.pm untested

filter: Statementstmt 0.0% 0 / 97 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 150 CC 9 SCAR 25.4
CC
9
Cov
0%
do_extract
42.0
can_build
12.0
do_build
6.0
CRAP 12.7
1 # Copyright © 2008 Raphaël Hertzog <hertzog@debian.org>
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, see <https://www.gnu.org/licenses/>.
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Dpkg::Source::Package::V3::Native - class for source format 3.0 (native)
21  
22 =head1 DESCRIPTION
23  
24 This module provides a class to handle the source package format 3.0 (native).
25  
26 B<Note>: This is a private module, its API can change at any time.
27  
28 =cut
29  
30 package Dpkg::Source::Package::V3::Native 0.01;
31  
32 use v5.36;
33  
34 use Cwd;
35 use File::Basename;
36 use File::Spec;
37 use File::Temp;
38  
39 use Dpkg::Gettext;
40 use Dpkg::ErrorHandling;
41 use Dpkg::Compression;
42 use Dpkg::Exit qw(push_exit_handler pop_exit_handler);
43 use Dpkg::Version;
44 use Dpkg::Source::Archive;
45 use Dpkg::Source::Functions qw(erasedir);
46 use Dpkg::Vendor qw(run_vendor_hook);
47  
48 use parent qw(Dpkg::Source::Package);
49  
50 sub CURRENT_MINOR_VERSION {
51 '0';
52 }
53  
54 sub do_extract {
55 my ($self, $newdirectory) = @_;
56 my $sourcestyle = $self->{options}{sourcestyle};
57 my $fields = $self->{fields};
58  
59 my $basename = $self->get_basename();
60 my $basenamerev = $self->get_basename(1);
61  
62 my $tarfile;
63 my $comp_ext_regex = compression_get_file_extension_regex();
64 foreach my $file ($self->get_files()) {
65 if ($file =~ /^\Q$basenamerev\E\.tar\.$comp_ext_regex$/) {
66 error(g_('multiple tarfiles in native source package')) if $tarfile;
67 $tarfile = $file;
68 } else {
69 error(g_('unrecognized file for a native source package: %s'), $file);
70 }
71 }
72  
73 error(g_('no tarfile in Files field')) unless $tarfile;
74  
75 my $v = Dpkg::Version->new($fields->{'Version'});
76 if ($v->has_revision()) {
77 warning(g_('native package version may not have a revision'));
78 }
79  
80 if ($self->{options}{no_overwrite_dir} and -e $newdirectory) {
81 error(g_('unpack target exists: %s'), $newdirectory);
82 } else {
83 erasedir($newdirectory);
84 }
85  
86 info(g_('unpacking %s'), $tarfile);
87 my $tar = Dpkg::Source::Archive->new(
88 filename => File::Spec->catfile($self->{basedir}, $tarfile),
89 );
90 $tar->extract($newdirectory);
91 }
92  
93 sub can_build {
94 my ($self, $dir) = @_;
95  
96 my $v = Dpkg::Version->new($self->{fields}->{'Version'});
97 if ($v->has_revision()) {
98 if (run_vendor_hook('has-fuzzy-native-source')) {
99 warning(g_('native package version may not have a revision'));
100 } else {
101 return (0, g_('native package version may not have a revision'));
102 }
103 }
104  
105 return 1;
106 }
107  
108 sub do_build {
109 my ($self, $dir) = @_;
110 my @tar_ignore = map { "--exclude=$_" } @{$self->{options}{tar_ignore}};
111 my @argv = @{$self->{options}{ARGV}};
112  
113 if (scalar(@argv)) {
114 usageerr(g_("-b takes only one parameter with format '%s'"),
115 $self->{fields}{'Format'});
116 }
117  
118 my $sourcepackage = $self->{fields}{'Source'};
119 my $basenamerev = $self->get_basename(1);
120 my $tarname = File::Spec->catfile($self->{basedir}, "$basenamerev.tar." . $self->{options}{comp_ext});
121  
122 info(g_('building %s in %s'), $sourcepackage, $tarname);
123  
124 my $newtar = File::Temp->new(
125 TEMPLATE => "$tarname.new.XXXXXX",
126 DIR => getcwd(),
127 UNLINK => 0,
128 );
129 push_exit_handler(sub { unlink($newtar) });
130  
131 my ($dirname, $dirbase) = fileparse($dir);
132 my $tar = Dpkg::Source::Archive->new(
133 filename => $newtar,
134 compression => compression_guess_from_filename($tarname),
135 compression_level => $self->{options}{comp_level},
136 );
137 $tar->create(
138 options => \@tar_ignore,
139 chdir => $dirbase,
140 );
141 $tar->add_directory($dirname);
142 $tar->finish();
143 rename($newtar, $tarname)
144 or syserr(g_("cannot rename '%s' (newly created) to '%s'"),
145 $newtar, $tarname);
146 pop_exit_handler();
147 chmod(0o666 &~ umask(), $tarname)
148 or syserr(g_("cannot change permission of '%s'"), $tarname);
149  
150 $self->add_file($tarname);
151 }
152  
153 =head1 CHANGES
154  
155 =head2 Version 0.xx
156  
157 This is a private module.
158  
159 =cut
160  
161 1;