Dpkg/Source/Package.pm

filter: Statementstmt 25.9% 72 / 278 Branchbran 7.5% 6 / 80 Conditioncond 1.3% 1 / 72 MC/DCmcdc 0.0% 0 / 40 Subroutinesub 40.0% 20 / 50 Podpod 43.7% 14 / 32 totaltotal 20.4% 113 / 552 CC 82 SCAR 43.8
CC
82
Cov
18%
extract
240.0
init_options
210.0
find_original_tarballs
132.0
CRAP 80.1
« Dpkg/Source/Package/V3/Git.pm ↑ Summary Dpkg/Deps/Simple.pm »
1 # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2008-2025 Guillem Jover <guillem@debian.org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 Dpkg::Source::Package - manipulate Debian source packages
22  
23 =head1 DESCRIPTION
24  
25 This module provides a class that can manipulate Debian source
26 packages. While it supports both the extraction and the creation
27 of source packages, the only API that is officially supported
28 is the one that supports the extraction of the source package.
29  
30 =cut
31  
32 package Dpkg::Source::Package 2.04;
33  
34 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 our @EXPORT_OK = qw(
37 get_default_diff_ignore_regex
38 set_default_diff_ignore_regex
39 get_default_tar_ignore_pattern
40 );
41  
42 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use File::Copy qw(cp);
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use Dpkg::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Dpkg::Checksums;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Dpkg::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Dpkg::Compression;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use Dpkg::Path qw(check_files_are_the_same check_directory_traversal);
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Dpkg::Vendor qw(run_vendor_hook);
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Dpkg::Source::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Dpkg::OpenPGP;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use Dpkg::OpenPGP::ErrorCodes;
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 1 my $diff_ignore_default_regex = '
61 # Ignore general backup files.
62 (?:^|/).*~$|
63 # Ignore emacs recovery files.
64 (?:^|/)\.#.*$|
65 # Ignore vi swap files.
66 (?:^|/)\..*\.sw.$|
67 # Ignore baz-style junk files or directories.
68 (?:^|/),,.*(?:$|/.*$)|
69 # File-names that should be ignored (never directories).
70 (?:^|/)(?:DEADJOE|\.arch-inventory|\.(?:bzr|cvs|hg|git|mtn-)ignore)$|
71 # File or directory names that should be ignored.
72 (?:^|/)(?:CVS|RCS|\.deps|\{arch\}|\.arch-ids|\.svn|
73 \.hg(?:tags|sigs)?|_darcs|\.git(?:attributes|modules|review)?|
74 \.mailmap|\.shelf|_MTN|\.be|\.bzr(?:\.backup|tags)?)(?:$|/.*$)
75 ';
76 # Take out comments and newlines.
77 1 $diff_ignore_default_regex =~ s/^#.*$//mg;
78 1 $diff_ignore_default_regex =~ s/\n//sg;
79  
80 1 ▶no warnings 'qw'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 my @tar_ignore_default_pattern = qw(
82 *.a
83 *.la
84 *.o
85 *.so
86 .*.sw?
87 */*~
88 ,,*
89 .[#~]*
90 .arch-ids
91 .arch-inventory
92 .be
93 .bzr
94 .bzr.backup
95 .bzr.tags
96 .bzrignore
97 .cvsignore
98 .deps
99 .git
100 .gitattributes
101 .gitignore
102 .gitmodules
103 .gitreview
104 .hg
105 .hgignore
106 .hgsigs
107 .hgtags
108 .mailmap
109 .mtn-ignore
110 .shelf
111 .svn
112 CVS
113 DEADJOE
114 RCS
115 _MTN
116 _darcs
117 {arch}
118 );
119 ## use critic
120  
121 =head1 FUNCTIONS
122  
123 =over 4
124  
125 =item $string = get_default_diff_ignore_regex()
126  
127 Returns the default diff ignore regex.
128  
129 =cut
130  
131 0 ▶sub get_default_diff_ignore_regex {
Subroutine get_default_diff_ignore_regex: not called CC=1 SCAR=6.9
Pod documented
132 0 return $diff_ignore_default_regex;
133 }
134  
135 =item set_default_diff_ignore_regex($string)
136  
137 Set a regex as the new default diff ignore regex.
138  
139 =cut
140  
141 0 ▶sub set_default_diff_ignore_regex {
Subroutine set_default_diff_ignore_regex: not called CC=1 SCAR=6.9
Pod documented
142 0 my $regex = shift;
143  
144 0 $diff_ignore_default_regex = $regex;
145 }
146  
147 =item @array = get_default_tar_ignore_pattern()
148  
149 Returns the default tar ignore pattern, as an array.
150  
151 =cut
152  
153 0 ▶sub get_default_tar_ignore_pattern {
Subroutine get_default_tar_ignore_pattern: not called CC=1 SCAR=6.9
Pod documented
154 0 return @tar_ignore_default_pattern;
155 }
156  
157 =back
158  
159 =head1 METHODS
160  
161 =over 4
162  
163 =item $src_pkg = Dpkg::Source::Package->new(%opts, options => {})
164  
165 Creates a new object corresponding to a source package.
166  
167 Options:
168  
169 =over
170  
171 =item B<filename>
172  
173 When set to a F<.dsc> file, it will be used to initialize the
174 source package with its description.
175  
176 =item B<format>
177  
178 If set to a valid value, and no filename has been specified,
179 the object will be initialized for that format (since dpkg 1.19.3).
180  
181 =item B<options>
182  
183 A hash ref which supports the following source package format options:
184  
185 =over 8
186  
187 =item B<skip_debianization>
188  
189 If set to 1, do not apply Debian changes on the extracted source package.
190  
191 =item B<skip_patches>
192  
193 If set to 1, do not apply Debian-specific patches. This options is
194 specific for source packages using format "2.0" and "3.0 (quilt)".
195  
196 =item B<certs>
197  
198 An array ref with a list of certificate keyrings to use for signature
199 verification.
200  
201 =item B<use_vendor_certs>
202  
203 If set to 0, the check_signature() method will not use vendor specific
204 keyrings, only user supplied ones.
205  
206 =item B<require_valid_signature>
207  
208 If set to 1, the check_signature() method will be stricter and will error
209 out if the signature can't be verified.
210  
211 =item B<require_strong_checksums>
212  
213 If set to 1, the check_checksums() method will be stricter and will error
214 out if there is no strong checksum.
215  
216 =item B<copy_orig_tarballs>
217  
218 If set to 1, the extraction will copy the upstream tarballs next the
219 target directory. This is useful if you want to be able to rebuild the
220 source package after its extraction.
221  
222 =back
223  
224 =back
225  
226 =cut
227  
228 1 ▶sub new {
Subroutine new: called CC=7 SCAR=26.7
Pod documented
229 1 my ($this, %opts) = @_;
230 1 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
231 1 my $self = {
232 fields => Dpkg::Control->new(type => CTRL_DSC),
233 format => Dpkg::Source::Format->new(),
234 options => {},
235 checksums => Dpkg::Checksums->new(),
236 openpgp => Dpkg::OpenPGP->new(
237 needs => {
238 api => 'verify',
239 },
240 ),
241 };
242 1 bless $self, $class;
243 1 ▶ if (exists $opts{options}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"options"}) 0 1 1
244 0 $self->{options} = $opts{options};
245 }
246 1 ▶ if (exists $opts{filename}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $opts{'filename'}) { } 0 1 1
elsif ($opts{'format'}) { } 0 1 1
247 0 $self->initialize($opts{filename});
248 0 $self->init_options();
249 } elsif ($opts{format}) {
250 0 $self->{fields}{Format} = $opts{format};
251 0 ▶ $self->{basedir} = $opts{basedir} // '.';
Condition0%0/2
$opts{"basedir"} // "."
l!l
00
MC/DC0%0/1
$opts{"basedir"} // "."
$opts{"basedir"}
Truth table0%0/2
A
A= $opts{"basedir"}
Aresult
11
00
252 0 $self->upgrade_object_type(0);
253 0 $self->init_options();
254 }
255  
256 1 ▶ if ($self->{options}{require_valid_signature}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'options'}{'require_valid_signature'}) { } 0 1 1
257 0 $self->{report_verify} = \&error;
258 } else {
259 1 $self->{report_verify} = \&warning;
260 }
261  
262 1 return $self;
263 }
264  
265 0 ▶sub init_options {
Subroutine init_options: not called CC=14 SCAR=53.5
Pod undocumented
266 0 my $self = shift;
267 # Use full ignore list by default.
268 # Note: This function is not called by V1 packages.
269 0 ▶ $self->{options}{diff_ignore_regex} ||= $diff_ignore_default_regex;
Condition0%0/3
$self->{"options"}{"diff_ignore_regex"} ||= $diff_ignore_default_regex
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"options"}{"diff_ignore_regex"} ||= $diff_ignore_default_regex
$self->{"options"}{"diff_ignore_regex"} $diff_ignore_default_regex
Truth table0%0/3
A ||= B
A= $self->{"options"}{"diff_ignore_regex"}B= $diff_ignore_default_regex
ABresult
1X1
011
000
270 0 $self->{options}{diff_ignore_regex} .= '|(?:^|/)debian/source/local-.*$';
271 0 $self->{options}{diff_ignore_regex} .= '|(?:^|/)debian/files(?:\.new)?$';
272 0 ▶ if (defined $self->{options}{tar_ignore}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'options'}{'tar_ignore'}) { } 0 0 0
273 $self->{options}{tar_ignore} = [ @tar_ignore_default_pattern ]
274 0 ▶ unless @{$self->{options}{tar_ignore}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"options"}{"tar_ignore"};} 0 0 0
275 } else {
276 0 $self->{options}{tar_ignore} = [ @tar_ignore_default_pattern ];
277 }
278 0 push @{$self->{options}{tar_ignore}},
279 'debian/source/local-options',
280 'debian/source/local-patch-header',
281 'debian/files',
282 'debian/files.new';
283 0 ▶ $self->{options}{copy_orig_tarballs} //= 0;
Condition0%0/2
$self->{"options"}{"copy_orig_tarballs"} //= 0
l!l
00
MC/DC0%0/1
$self->{"options"}{"copy_orig_tarballs"} //= 0
$self->{"options"}{"copy_orig_tarballs"}
Truth table0%0/2
A
A= $self->{"options"}{"copy_orig_tarballs"}
Aresult
11
00
284  
285 # Skip debianization while specific to some formats has an impact.
286 # on code common to all formats.
287 0 ▶ $self->{options}{skip_debianization} //= 0;
Condition0%0/2
$self->{"options"}{"skip_debianization"} //= 0
l!l
00
MC/DC0%0/1
$self->{"options"}{"skip_debianization"} //= 0
$self->{"options"}{"skip_debianization"}
Truth table0%0/2
A
A= $self->{"options"}{"skip_debianization"}
Aresult
11
00
288 0 ▶ $self->{options}{skip_patches} //= 0;
Condition0%0/2
$self->{"options"}{"skip_patches"} //= 0
l!l
00
MC/DC0%0/1
$self->{"options"}{"skip_patches"} //= 0
$self->{"options"}{"skip_patches"}
Truth table0%0/2
A
A= $self->{"options"}{"skip_patches"}
Aresult
11
00
289  
290 # Set default validation checks.
291 0 ▶ $self->{options}{certs} //= [];
Condition0%0/2
$self->{"options"}{"certs"} //= []
l!l
00
MC/DC0%0/1
$self->{"options"}{"certs"} //= []
$self->{"options"}{"certs"}
Truth table0%0/2
A
A= $self->{"options"}{"certs"}
Aresult
11
00
292 0 ▶ $self->{options}{use_vendor_certs} //= 1;
Condition0%0/2
$self->{"options"}{"use_vendor_certs"} //= 1
l!l
00
MC/DC0%0/1
$self->{"options"}{"use_vendor_certs"} //= 1
$self->{"options"}{"use_vendor_certs"}
Truth table0%0/2
A
A= $self->{"options"}{"use_vendor_certs"}
Aresult
11
00
293 0 ▶ $self->{options}{require_valid_signature} //= 0;
Condition0%0/2
$self->{"options"}{"require_valid_signature"} //= 0
l!l
00
MC/DC0%0/1
$self->{"options"}{"require_valid_signature"} //= 0
$self->{"options"}{"require_valid_signature"}
Truth table0%0/2
A
A= $self->{"options"}{"require_valid_signature"}
Aresult
11
00
294 0 ▶ $self->{options}{require_strong_checksums} //= 0;
Condition0%0/2
$self->{"options"}{"require_strong_checksums"} //= 0
l!l
00
MC/DC0%0/1
$self->{"options"}{"require_strong_checksums"} //= 0
$self->{"options"}{"require_strong_checksums"}
Truth table0%0/2
A
A= $self->{"options"}{"require_strong_checksums"}
Aresult
11
00
295  
296 # Set default compressor for new formats.
297 0 ▶ $self->{options}{compression} //= 'xz';
Condition0%0/2
$self->{"options"}{"compression"} //= "xz"
l!l
00
MC/DC0%0/1
$self->{"options"}{"compression"} //= "xz"
$self->{"options"}{"compression"}
Truth table0%0/2
A
A= $self->{"options"}{"compression"}
Aresult
11
00
298 0 ▶ $self->{options}{comp_level} //= compression_get_level($self->{options}{compression});
Condition0%0/3
$self->{"options"}{"comp_level"} //= compression_get_level($self->{"options"}{"compression"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"options"}{"comp_level"} //= compression_get_level($self->{"options"}{"compression"})
$self->{"options"}{"comp_level"} compression_get_level($self->{"options"}{"compression"})
Truth table0%0/3
A //= B
A= $self->{"options"}{"comp_level"}B= compression_get_level($self->{"options"}{"compression"})
ABresult
1X1
011
000
299 0 ▶ $self->{options}{comp_ext} //= compression_get_file_extension($self->{options}{compression});
Condition0%0/3
$self->{"options"}{"comp_ext"} //= compression_get_file_extension($self->{"options"}{"compression"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"options"}{"comp_ext"} //= compression_get_file_extension($self->{"options"}{"compression"})
$self->{"options"}{"comp_ext"} compression_get_file_extension($self->{"options"}{"compression"})
Truth table0%0/3
A //= B
A= $self->{"options"}{"comp_ext"}B= compression_get_file_extension($self->{"options"}{"compression"})
ABresult
1X1
011
000
300 }
301  
302 0 ▶sub initialize {
Subroutine initialize: not called CC=5 SCAR=34.0
Pod undocumented
303 0 my ($self, $filename) = @_;
304 0 my ($fn, $dir) = fileparse($filename);
305 0 ▶ error(g_('%s is not the name of a file'), $filename) unless $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless $fn 0 0 0
306 0 ▶ $self->{basedir} = $dir || '.';
Condition0%0/2
$dir || '.'
l!l
00
MC/DC0%0/1
$dir || '.'
$dir
Truth table0%0/2
A
A= $dir
Aresult
11
00
307 0 $self->{filename} = $fn;
308  
309 # Read the fields.
310 0 my $fields = $self->{fields};
311 0 $fields->load($filename);
312 0 $self->{is_signed} = $fields->get_option('is_pgp_signed');
313  
314 0 foreach my $f (qw(Source Version Files)) {
315 0 ▶ unless (defined($fields->{$f})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{$f}) 0 0 0
316 0 error(g_('missing critical source control field %s'), $f);
317 }
318 }
319  
320 0 $self->{checksums}->add_from_control($fields, use_files_for_md5 => 1);
321  
322 0 $self->upgrade_object_type(0);
323 }
324  
325 0 ▶sub upgrade_object_type {
Subroutine upgrade_object_type: not called CC=7 SCAR=40.3
Pod undocumented
326 0 my ($self, $update_format) = @_;
327 0 ▶ $update_format //= 1;
Condition0%0/2
$update_format //= 1
l!l
00
MC/DC0%0/1
$update_format //= 1
$update_format
Truth table0%0/2
A
A= $update_format
Aresult
11
00
328  
329 0 ▶ my $format = $self->{fields}{'Format'} // '1.0';
Condition0%0/2
$self->{"fields"}{"Format"} // "1.0"
l!l
00
MC/DC0%0/1
$self->{"fields"}{"Format"} // "1.0"
$self->{"fields"}{"Format"}
Truth table0%0/2
A
A= $self->{"fields"}{"Format"}
Aresult
11
00
330 0 my ($major, $minor, $variant) = $self->{format}->set($format);
331  
332 0 my $module = "Dpkg::Source::Package::V$major";
333 0 ▶ $module .= '::' . ucfirst $variant if defined $variant;
Branch: 1 branch
BranchTrueFalseTotal
if defined $variant 0 0 0
334 0 eval qq{
335 require $module;
336 };
337 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
338 0 error(g_("source package format '%s' is not supported: %s"),
339 $format, $@);
340 }
341 0 ▶ if ($update_format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($update_format) 0 0 0
342 0 $minor = $module->CURRENT_MINOR_VERSION();
343 0 $self->{format}->set_from_parts($major, $minor, $variant);
344 0 $self->{fields}{'Format'} = $self->{format}->get();
345 }
346  
347 0 ▶ $module->prerequisites() if $module->can('prerequisites');
Branch: 1 branch
BranchTrueFalseTotal
if $module->can("prerequisites") 0 0 0
348 0 bless $self, $module;
349 }
350  
351 =item $filename = $src_pkg->get_filename()
352  
353 Returns the filename of the DSC file.
354  
355 =cut
356  
357 0 ▶sub get_filename {
Subroutine get_filename: not called CC=1 SCAR=6.9
Pod documented
358 0 my $self = shift;
359 0 return File::Spec->catfile($self->{basedir}, $self->{filename});
360 }
361  
362 =item @files_list = $src_pkg->get_files()
363  
364 Returns the list of files referenced by the source package. The filenames
365 usually do not have any path information.
366  
367 =cut
368  
369 0 ▶sub get_files {
Subroutine get_files: not called CC=1 SCAR=6.9
Pod documented
370 0 my $self = shift;
371 0 return $self->{checksums}->get_files();
372 }
373  
374 =item $src_pkg->check_checksums()
375  
376 Verify the checksums embedded in the DSC file. It requires the presence of
377 the other files constituting the source package. If any inconsistency is
378 discovered, it immediately errors out. It will make sure at least one strong
379 checksum is present.
380  
381 If the object has been created with the "require_strong_checksums" option,
382 then any problem will result in a fatal error.
383  
384 =cut
385  
386 0 ▶sub check_checksums {
Subroutine check_checksums: not called CC=5 SCAR=34.0
Pod documented
387 0 my $self = shift;
388 0 my $checksums = $self->{checksums};
389 0 my $warn_on_weak = 0;
390  
391 # The add_from_file() call verifies the checksums if they already exist.
392 0 foreach my $file ($checksums->get_files()) {
393 0 ▶ if (not $checksums->has_strong_checksums($file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($checksums->has_strong_checksums($file)) 0 0 0
394 0 ▶ if ($self->{options}{require_strong_checksums}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'options'}{'require_strong_checksums'}) { } 0 0 0
395 0 error(g_('source package uses only weak checksums'));
396 } else {
397 0 $warn_on_weak = 1;
398 }
399 }
400 0 my $pathname = File::Spec->catfile($self->{basedir}, $file);
401 0 $checksums->add_from_file($pathname, key => $file);
402 }
403  
404 0 ▶ warning(g_('source package uses only weak checksums')) if $warn_on_weak;
Branch: 1 branch
BranchTrueFalseTotal
if $warn_on_weak 0 0 0
405 }
406  
407 0 ▶sub get_basename {
Subroutine get_basename: not called CC=3 SCAR=24.8
Pod undocumented
408 0 my ($self, $with_revision) = @_;
409 0 my $f = $self->{fields};
410 0 ▶ unless (exists $f->{'Source'} and exists $f->{'Version'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $f->{"Source"} and exists $f->{"Version"}) 0 0 0
Condition0%0/3
exists $f->{"Source"} and exists $f->{"Version"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $f->{"Source"} and exists $f->{"Version"}
exists $f->{"Source"} exists $f->{"Version"}
Truth table0%0/3
A and B
A= exists $f->{"Source"}B= exists $f->{"Version"}
ABresult
0X0
100
111
411 0 error(g_('%s and %s fields are required to compute the source basename'),
412 'Source', 'Version');
413 }
414 0 my $v = Dpkg::Version->new($f->{'Version'});
415 0 my $vs = $v->as_string(
416 omit_epoch => 1,
417 omit_revision => ! $with_revision,
418 );
419 0 return $f->{'Source'} . '_' . $vs;
420 }
421  
422 =item $pathname = $src_pkg->get_basedirname()
423  
424 Returns the default base directory name for the package.
425  
426 =cut
427  
428 0 ▶sub get_basedirname {
Subroutine get_basedirname: not called CC=1 SCAR=6.9
Pod documented
429 0 my $self = shift;
430  
431 0 my $dirname = $self->get_basename();
432 0 $dirname =~ s/_/-/;
433  
434 0 return $dirname;
435 }
436  
437 0 ▶sub find_original_tarballs {
Subroutine find_original_tarballs: not called CC=11 SCAR=48.8
Pod undocumented
438 0 my ($self, %opts) = @_;
439 0 ▶ $opts{extension} //= compression_get_file_extension_regex();
Condition0%0/3
$opts{"extension"} //= compression_get_file_extension_regex()
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"extension"} //= compression_get_file_extension_regex()
$opts{"extension"} compression_get_file_extension_regex()
Truth table0%0/3
A //= B
A= $opts{"extension"}B= compression_get_file_extension_regex()
ABresult
1X1
011
000
440 0 ▶ $opts{include_main} //= 1;
Condition0%0/2
$opts{"include_main"} //= 1
l!l
00
MC/DC0%0/1
$opts{"include_main"} //= 1
$opts{"include_main"}
Truth table0%0/2
A
A= $opts{"include_main"}
Aresult
11
00
441 0 ▶ $opts{include_supplementary} //= 1;
Condition0%0/2
$opts{"include_supplementary"} //= 1
l!l
00
MC/DC0%0/1
$opts{"include_supplementary"} //= 1
$opts{"include_supplementary"}
Truth table0%0/2
A
A= $opts{"include_supplementary"}
Aresult
11
00
442 0 my $basename = $self->get_basename();
443 0 my @tar;
444 0 foreach my $dir ($self->{basedir}, $self->{options}{origtardir}) {
445 0 ▶ next unless defined($dir) and -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and -d $dir 0 0 0
Condition0%0/3
defined $dir and -d $dir
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dir and -d $dir
defined $dir -d $dir
Truth table0%0/3
A and B
A= defined $dirB= -d $dir
ABresult
0X0
100
111
446 0 ▶ opendir(my $dir_dh, $dir)
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir_dh, $dir or syserr(g_("cannot open directory %s"), $dir) 0 0 0
447 or syserr(g_('cannot open directory %s'), $dir);
448 0 push @tar, map { File::Spec->catfile($dir, $_) } grep {
449 0 ($opts{include_main} and
450 /^\Q$basename\E\.orig\.tar\.$opts{extension}$/) or
451 ($opts{include_supplementary} and
452 0 ▶ /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{extension}$/)
Condition0%0/9
$opts{'include_main'} && /^\Q$basename\E\.orig\.tar\.$opts{'extension'}$/u || $opts{'include_supplementary'} && /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{'extension'}$/u
l!l&&r!l&&!r
000
$opts{"include_main"} and /^\Q$basename\E\.orig\.tar\.$opts{"extension"}$/u
!ll&&!rl&&r
000
$opts{"include_supplementary"} and /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{"extension"}$/u
!ll&&!rl&&r
000
MC/DC0%0/4
$opts{'include_main'} && /^\Q$basename\E\.orig\.tar\.$opts{'extension'}$/u || $opts{'include_supplementary'} && /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{'extension'}$/u
$opts{"include_main"} /^\Q$basename\E\.orig\.tar\.$opts{"extension"}$/u $opts{"include_supplementary"} /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{"extension"}$/u
Truth table0%0/7
A and B || C and D
A= $opts{"include_main"}B= /^\Q$basename\E\.orig\.tar\.$opts{"extension"}$/uC= $opts{"include_supplementary"}D= /^\Q$basename\E\.orig-[[:alnum:]-]+\.tar\.$opts{"extension"}$/u
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
453 } readdir($dir_dh);
454 0 closedir($dir_dh);
455 }
456 0 return @tar;
457 }
458  
459 =item $pathname = $src_pkg->get_upstream_signing_key($dir)
460  
461 Get the filename for the upstream key.
462  
463 =cut
464  
465 0 ▶sub get_upstream_signing_key {
Subroutine get_upstream_signing_key: not called CC=1 SCAR=6.9
Pod documented
466 0 my ($self, $dir) = @_;
467  
468 0 return "$dir/debian/upstream/signing-key.asc";
469 }
470  
471 =item $src_pkg->armor_original_tarball_signature($bin, $asc)
472  
473 Convert a signature from binary to ASCII armored form. If the signature file
474 does not exist, it is a no-op. If the signature file is already ASCII armored
475 then copy it, otherwise convert it from binary to ASCII armored form.
476  
477 =cut
478  
479 3 ▶sub armor_original_tarball_signature {
Subroutine armor_original_tarball_signature: called CC=2 SCAR=6.9
Pod documented
480 3 my ($self, $bin, $asc) = @_;
481  
482 3 ▶ if (-e $bin) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $bin) 2 1 3
483 2 return $self->{openpgp}->armor('SIGNATURE', $bin, $asc);
484 }
485  
486 1 return;
487 }
488  
489 =item $src_pkg->check_original_tarball_signature($dir, @asc)
490  
491 Verify the original upstream tarball signatures @asc using the upstream
492 public keys. It requires the origin upstream tarballs, their signatures
493 and the upstream signing key, as found in an unpacked source tree $dir.
494 If any inconsistency is discovered, it immediately errors out.
495  
496 =cut
497  
498 0 ▶sub check_original_tarball_signature {
Subroutine check_original_tarball_signature: not called CC=4 SCAR=30.0
Pod documented
499 0 my ($self, $dir, @asc) = @_;
500  
501 0 my $upstream_key = $self->get_upstream_signing_key($dir);
502 0 ▶ if (not -e $upstream_key) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $upstream_key) 0 0 0
503 0 warning(g_('upstream tarball signatures but no upstream signing key'));
504 0 return;
505 }
506  
507 0 foreach my $asc (@asc) {
508 0 my $datafile = $asc =~ s/\.asc$//r;
509  
510 0 info(g_('verifying %s'), $asc);
511 0 my $rc = $self->{openpgp}->verify($datafile, $asc, $upstream_key);
512 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
513 0 $self->{report_verify}->(g_('cannot verify upstream tarball signature for %s: %s'),
514 $datafile, openpgp_errorcode_to_string($rc));
515 }
516 }
517 }
518  
519 =item $bool = $src_pkg->is_signed()
520  
521 Returns 1 if the DSC files contains an embedded OpenPGP signature.
522 Otherwise returns 0.
523  
524 =cut
525  
526 0 ▶sub is_signed {
Subroutine is_signed: not called CC=1 SCAR=6.9
Pod documented
527 0 my $self = shift;
528 0 return $self->{is_signed};
529 }
530  
531 =item $src_pkg->check_signature()
532  
533 Implement the same OpenPGP signature check that dpkg-source does.
534 In case of problems, it prints a warning or errors out.
535  
536 If the object has been created with the "require_valid_signature" option,
537 then any problem will result in a fatal error.
538  
539 =cut
540  
541 0 ▶sub check_signature {
Subroutine check_signature: not called CC=7 SCAR=40.3
Pod documented
542 0 my $self = shift;
543 0 my $dsc = $self->get_filename();
544 0 my @certs;
545  
546 0 info(g_('verifying %s'), $dsc);
547  
548 # User specified signer certificates, otherwise fallback to use the
549 # trusted keyrings.
550 0 ▶ if (@{$self->{options}{certs}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'options'}{'certs'};}) { } 0 0 0
551 0 push @certs, @{$self->{options}{certs}};
552 } else {
553 0 foreach my $keyring ($self->{openpgp}->get_trusted_keyrings()) {
554 0 push @certs, $keyring;
555 0 warning(g_('using implicit trusted keyring %s is deprecated; ' .
556 'use --signer-cert with an OpenPGP keyring instead'),
557 $keyring);
558 }
559 }
560  
561 0 ▶ if ($self->{options}{use_vendor_certs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"use_vendor_certs"}) 0 0 0
562 0 foreach my $vendor_keyring (run_vendor_hook('package-keyrings')) {
563 0 ▶ if (-r $vendor_keyring) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $vendor_keyring) { } 0 0 0
564 0 push @certs, $vendor_keyring;
565 0 info(g_('using keyring %s'), $vendor_keyring);
566 } else {
567 0 info(g_('skipping absent keyring %s'), $vendor_keyring);
568 }
569 }
570 }
571  
572 0 my $rc = $self->{openpgp}->inline_verify($dsc, undef, @certs);
573 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
574 0 $self->{report_verify}->(g_('cannot verify inline signature for %s: %s'),
575 $dsc, openpgp_errorcode_to_string($rc));
576 }
577 }
578  
579 0 ▶sub describe_cmdline_options {
Subroutine describe_cmdline_options: not called CC=1 SCAR=6.9
Pod undocumented
580 0 return;
581 }
582  
583 0 ▶sub parse_cmdline_options {
Subroutine parse_cmdline_options: not called CC=3 SCAR=24.8
Pod undocumented
584 0 my ($self, @opts) = @_;
585 0 foreach my $option (@opts) {
586 0 ▶ if (not $self->parse_cmdline_option($option)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->parse_cmdline_option($option)) 0 0 0
587 0 warning(g_('%s is not a valid option for %s'), $option, ref $self);
588 }
589 }
590 }
591  
592 0 ▶sub parse_cmdline_option {
Subroutine parse_cmdline_option: not called CC=1 SCAR=6.9
Pod undocumented
593 0 return 0;
594 }
595  
596 =item $src_pkg->extract($targetdir)
597  
598 Extracts the source package in the target directory $targetdir. Beware
599 that if $targetdir already exists, it will be erased (as long as the
600 no_overwrite_dir option is set).
601  
602 =cut
603  
604 0 ▶sub extract {
Subroutine extract: not called CC=15 SCAR=54.8
Pod documented
605 0 my ($self, $newdirectory) = @_;
606  
607 0 my ($ok, $error) = version_check($self->{fields}{'Version'});
608 0 ▶ if (not $ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
609 0 ▶ if ($self->{options}{ignore_bad_version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'options'}{'ignore_bad_version'}) { } 0 0 0
610 0 warning($error);
611 } else {
612 0 error($error);
613 }
614 }
615  
616 # Copy orig tarballs.
617 0 ▶ if ($self->{options}{copy_orig_tarballs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"copy_orig_tarballs"}) 0 0 0
618 0 my $basename = $self->get_basename();
619 0 my ($dirname, $destdir) = fileparse($newdirectory);
620 0 ▶ $destdir ||= '.';
Condition0%0/2
$destdir ||= "."
l!l
00
MC/DC0%0/1
$destdir ||= "."
$destdir
Truth table0%0/2
A
A= $destdir
Aresult
11
00
621 0 my $ext = compression_get_file_extension_regex();
622 0 foreach my $orig (grep { /^\Q$basename\E\.orig(-[[:alnum:]-]+)?\.tar\.$ext$/ }
623 $self->get_files())
624 {
625 0 my $src = File::Spec->catfile($self->{basedir}, $orig);
626 0 my $dst = File::Spec->catfile($destdir, $orig);
627 0 ▶ if (not check_files_are_the_same($src, $dst, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (check_files_are_the_same($src, $dst, 1)) 0 0 0
628 0 ▶ cp($src, $dst)
Branch: 1 branch
BranchTrueFalseTotal
cp($src, $dst) or syserr(g_("cannot copy %s to %s"), $src, $dst) 0 0 0
629 or syserr(g_('cannot copy %s to %s'), $src, $dst);
630 }
631 }
632 }
633  
634 # Try extract.
635 0 $self->do_extract($newdirectory);
636  
637 # Check for directory traversals.
638 0 ▶ if (not $self->{options}{skip_debianization} and not $self->{no_check}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"options"}{"skip_debianization"} or $self->{"no_check"}) 0 0 0
Condition0%0/3
$self->{"options"}{"skip_debianization"} or $self->{"no_check"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"options"}{"skip_debianization"} or $self->{"no_check"}
$self->{"options"}{"skip_debianization"} $self->{"no_check"}
Truth table0%0/3
A or B
A= $self->{"options"}{"skip_debianization"}B= $self->{"no_check"}
ABresult
1X1
011
000
639 # We need to add a trailing slash to handle the debian directory
640 # possibly being a symlink.
641 0 check_directory_traversal($newdirectory, "$newdirectory/debian/");
642 }
643  
644 # Store format if non-standard so that next build keeps the same format.
645 0 ▶ if ($self->{fields}{'Format'} and
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fields"}{"Format"} and $self->{"fields"}{"Format"} ne "1.0" and not $self->{"options"}{"skip_debianization"}) 0 0 0
Condition0%0/6
$self->{"fields"}{"Format"} and $self->{"fields"}{"Format"} ne "1.0" and not $self->{"options"}{"skip_debianization"}
!ll&&!rl&&r
000
$self->{"fields"}{"Format"} and $self->{"fields"}{"Format"} ne "1.0"
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"fields"}{"Format"} and $self->{"fields"}{"Format"} ne "1.0" and not $self->{"options"}{"skip_debianization"}
$self->{"fields"}{"Format"} $self->{"fields"}{"Format"} ne "1.0" not $self->{"options"}{"skip_debianization"}
Truth table0%0/4
A and B and not(C)
A= $self->{"fields"}{"Format"}B= $self->{"fields"}{"Format"} ne "1.0"C= not $self->{"options"}{"skip_debianization"}
ABCresult
0XX0
10X0
1100
1111
646 $self->{fields}{'Format'} ne '1.0' and
647 not $self->{options}{skip_debianization})
648 {
649 0 my $srcdir = File::Spec->catdir($newdirectory, 'debian', 'source');
650 0 my $format_file = File::Spec->catfile($srcdir, 'format');
651 0 ▶ unless (-e $format_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $format_file) 0 0 0
652 0 ▶ mkdir($srcdir) unless -e $srcdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $srcdir 0 0 0
653 0 $self->{format}->save($format_file);
654 }
655 }
656 }
657  
658 0 ▶sub do_extract {
Subroutine do_extract: not called CC=1 SCAR=6.9
Pod undocumented
659 0 croak 'Dpkg::Source::Package does not know how to unpack a ' .
660 'source package; use one of the subclasses';
661 }
662  
663 # Function used specifically during creation of a source package.
664  
665 0 ▶sub before_build {
Subroutine before_build: not called CC=1 SCAR=6.9
Pod undocumented
666 0 my ($self, $dir) = @_;
667 }
668  
669 0 ▶sub build {
Subroutine build: not called CC=1 SCAR=6.9
Pod undocumented
670 0 my ($self, @args) = @_;
671  
672 0 $self->do_build(@args);
673 }
674  
675 0 ▶sub after_build {
Subroutine after_build: not called CC=1 SCAR=6.9
Pod undocumented
676 0 my ($self, $dir) = @_;
677 }
678  
679 0 ▶sub do_build {
Subroutine do_build: not called CC=1 SCAR=6.9
Pod undocumented
680 0 croak 'Dpkg::Source::Package does not know how to build a ' .
681 'source package; use one of the subclasses';
682 }
683  
684 0 ▶sub can_build {
Subroutine can_build: not called CC=1 SCAR=6.9
Pod undocumented
685 0 my ($self, $dir) = @_;
686 0 return (0, 'can_build() has not been overridden');
687 }
688  
689 0 ▶sub add_file {
Subroutine add_file: not called CC=2 SCAR=17.9
Pod undocumented
690 0 my ($self, $filename) = @_;
691 0 my ($fn, $dir) = fileparse($filename);
692 0 ▶ if ($self->{checksums}->has_file($fn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"checksums"}->has_file($fn)) 0 0 0
693 0 croak "tried to add file '$fn' twice";
694 }
695 0 $self->{checksums}->add_from_file($filename, key => $fn);
696 $self->{checksums}->export_to_control($self->{fields},
697 0 use_files_for_md5 => 1,
698 );
699 }
700  
701 0 ▶sub commit {
Subroutine commit: not called CC=1 SCAR=6.9
Pod undocumented
702 0 my ($self, @args) = @_;
703  
704 0 $self->do_commit(@args);
705 }
706  
707 0 ▶sub do_commit {
Subroutine do_commit: not called CC=1 SCAR=6.9
Pod undocumented
708 0 my ($self, $dir) = @_;
709 info(g_("'%s' is not supported by the source format '%s'"),
710 0 'dpkg-source --commit', $self->{fields}{'Format'});
711 }
712  
713 0 ▶sub write_dsc {
Subroutine write_dsc: not called CC=10 SCAR=47.0
Pod undocumented
714 0 my ($self, %opts) = @_;
715 0 my $fields = $self->{fields};
716  
717 0 foreach my $f (keys %{$opts{override}}) {
718 0 $fields->{$f} = $opts{override}{$f};
719 }
720  
721 0 ▶ unless ($opts{no_check}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"no_check"}) 0 0 0
722 0 foreach my $f (qw(Source Version Architecture)) {
723 0 ▶ unless (defined($fields->{$f})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{$f}) 0 0 0
724 0 error(g_('missing information for critical output field %s'), $f);
725 }
726 }
727 0 foreach my $f (qw(Maintainer Standards-Version)) {
728 0 ▶ unless (defined($fields->{$f})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{$f}) 0 0 0
729 0 warning(g_('missing information for output field %s'), $f);
730 }
731 }
732 }
733  
734 0 foreach my $f (keys %{$opts{remove}}) {
735 0 delete $fields->{$f};
736 }
737  
738 0 my $filename = $opts{filename};
739 0 ▶ $filename //= File::Spec->catfile($self->{basedir}, $self->get_basename(1) . '.dsc');
Condition0%0/3
$filename //= "File::Spec"->catfile($self->{"basedir"}, $self->get_basename(1) . '.dsc')
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename //= "File::Spec"->catfile($self->{"basedir"}, $self->get_basename(1) . '.dsc')
$filename "File::Spec"->catfile($self->{"basedir"}, $self->get_basename(1) . '.dsc')
Truth table0%0/3
A //= B
A= $filenameB= "File::Spec"->catfile($self->{"basedir"}, $self->get_basename(1) . '.dsc')
ABresult
1X1
011
000
740 0 ▶ open(my $dsc_fh, '>', $filename)
Branch: 1 branch
BranchTrueFalseTotal
open my $dsc_fh, ">", $filename or syserr(g_("cannot write %s"), $filename) 0 0 0
741 or syserr(g_('cannot write %s'), $filename);
742 0 $fields->apply_substvars($opts{substvars});
743 0 $fields->output($dsc_fh);
744 0 close($dsc_fh);
745 }
746  
747 =back
748  
749 =head1 CHANGES
750  
751 =head2 Version 2.04 (dpkg 1.23.0)
752  
753 New options: certs, use_vendor_certs in $p->check_checksums().
754  
755 =head2 Version 2.03 (dpkg 1.22.7)
756  
757 New method: $p->get_basedirname().
758  
759 =head2 Version 2.02 (dpkg 1.21.10)
760  
761 New method: $p->armor_original_tarball_signature().
762  
763 =head2 Version 2.01 (dpkg 1.20.1)
764  
765 New method: $p->get_upstream_signing_key().
766  
767 =head2 Version 2.00 (dpkg 1.20.0)
768  
769 New method: $p->check_original_tarball_signature().
770  
771 Remove variable: $diff_ignore_default_regexp.
772  
773 Hide variable: @tar_ignore_default_pattern.
774  
775 =head2 Version 1.03 (dpkg 1.19.3)
776  
777 New option: format in new().
778  
779 =head2 Version 1.02 (dpkg 1.18.7)
780  
781 New option: require_strong_checksums in $p->check_checksums().
782  
783 =head2 Version 1.01 (dpkg 1.17.2)
784  
785 New functions: $p->get_default_diff_ignore_regex(),
786 $p->set_default_diff_ignore_regex(), $p->get_default_tar_ignore_pattern().
787  
788 Deprecated variables: $diff_ignore_default_regexp, @tar_ignore_default_pattern
789  
790 =head2 Version 1.00 (dpkg 1.16.1)
791  
792 Mark the module as public.
793  
794 =cut
795  
796 1 1;
« Dpkg/Source/Package/V3/Git.pm ↑ Summary Dpkg/Deps/Simple.pm »