| 1 | # Copyright © 2008-2012 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::Quilt - represent a quilt patch queue | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | This module provides a class to handle quilt patch queues. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | package Dpkg::Source::Quilt 0.02; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use List::Util qw(any none); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | use Fcntl qw(:mode); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | use File::stat (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | use File::Copy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use File::Path qw(make_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | use Dpkg::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | use Dpkg::Source::Patch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | use Dpkg::Vendor qw(get_current_vendor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 1 | my ($this, $dir, %opts) = @_; | |||||||||||||||||||||||||||
| 52 | 1 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | my $self = { | |||||||||||||||||||||||||||
| 55 | dir => $dir, | ||||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||
| 57 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | $self->load_series(); | |||||||||||||||||||||||||||
| 60 | 1 | $self->load_db(); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | return $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub setup_db { | ||||||||||||||||||||||||||
|
Subroutine
setup_db: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $db_dir = $self->get_db_dir(); | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (not -d $db_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | mkdir $db_dir or syserr(g_('cannot create directory %s'), $db_dir); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | my $file = $self->get_db_file('.version'); | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if (not -e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | file_dump($file, "2\n"); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | # The files below are used by quilt to know where patches are stored | ||||||||||||||||||||||||||||
| 76 | # and what file contains the patch list (supported by quilt >= 0.48-5 | ||||||||||||||||||||||||||||
| 77 | # in Debian). | ||||||||||||||||||||||||||||
| 78 | 0 | $file = $self->get_db_file('.quilt_patches'); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (not -e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | file_dump($file, "debian/patches\n"); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 0 | $file = $self->get_db_file('.quilt_series'); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (not -e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | my $series = $self->get_series_file(); | |||||||||||||||||||||||||||
| 85 | 0 | $series = (File::Spec->splitpath($series))[2]; | |||||||||||||||||||||||||||
| 86 | 0 | file_dump($file, "$series\n"); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | ▶ | sub load_db { | ||||||||||||||||||||||||||
|
Subroutine
load_db: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | my $pc_applied = $self->get_db_file('applied-patches'); | |||||||||||||||||||||||||||
| 94 | 1 | $self->{applied_patches} = [ $self->read_patch_list($pc_applied) ]; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub save_db { | ||||||||||||||||||||||||||
|
Subroutine
save_db: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | $self->setup_db(); | |||||||||||||||||||||||||||
| 101 | 0 | my $pc_applied = $self->get_db_file('applied-patches'); | |||||||||||||||||||||||||||
| 102 | 0 | $self->write_patch_list($pc_applied, $self->{applied_patches}); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub load_series { | ||||||||||||||||||||||||||
|
Subroutine
load_series: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 1 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | my $series = $self->get_series_file(); | |||||||||||||||||||||||||||
| 109 | 1 | $self->{series} = [ $self->read_patch_list($series, %opts) ]; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub series { | ||||||||||||||||||||||||||
|
Subroutine
series: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 1 | return @{$self->{series}}; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub applied { | ||||||||||||||||||||||||||
|
Subroutine
applied: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | 0 | return @{$self->{applied_patches}}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub top { | ||||||||||||||||||||||||||
|
Subroutine
top: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 0 | my $count = scalar @{$self->{applied_patches}}; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | return $self->{applied_patches}[$count - 1] if $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | return; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my ($self, $patch_name) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return if any { $_ eq $patch_name } @{$self->{series}}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # Add patch to series files. | ||||||||||||||||||||||||||||
| 135 | 0 | $self->setup_db(); | |||||||||||||||||||||||||||
| 136 | 0 | $self->_file_add_line($self->get_series_file(), $patch_name); | |||||||||||||||||||||||||||
| 137 | 0 | $self->_file_add_line($self->get_db_file('applied-patches'), $patch_name); | |||||||||||||||||||||||||||
| 138 | 0 | $self->load_db(); | |||||||||||||||||||||||||||
| 139 | 0 | $self->load_series(); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # Ensure quilt meta-data is created and in sync with some trickery: | ||||||||||||||||||||||||||||
| 142 | # Reverse-apply the patch, drop .pc/$patch, and re-apply it with the | ||||||||||||||||||||||||||||
| 143 | # correct options to recreate the backup files. | ||||||||||||||||||||||||||||
| 144 | 0 | $self->pop(reverse_apply => 1); | |||||||||||||||||||||||||||
| 145 | 0 | $self->push(); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub unregister { | ||||||||||||||||||||||||||
|
Subroutine
unregister: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 0 | my ($self, $patch_name) = @_; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return if none { $_ eq $patch_name } @{$self->{series}}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | my $series = $self->get_series_file(); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | $self->_file_drop_line($series, $patch_name); | |||||||||||||||||||||||||||
| 156 | 0 | $self->_file_drop_line($self->get_db_file('applied-patches'), $patch_name); | |||||||||||||||||||||||||||
| 157 | 0 | erasedir($self->get_db_file($patch_name)); | |||||||||||||||||||||||||||
| 158 | 0 | $self->load_db(); | |||||||||||||||||||||||||||
| 159 | 0 | $self->load_series(); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Clean up empty series. | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | unlink $series if -z $series; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | 0 | my $count_applied = scalar @{$self->{applied_patches}}; | |||||||||||||||||||||||||||
| 168 | 0 | my $count_series = scalar @{$self->{series}}; | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $self->{series}[$count_applied] if ($count_series > $count_applied); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | return; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | sub push { | ||||||||||||||||||||||||||
|
Subroutine
push: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 174 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | $opts{verbose} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"verbose"} //= 0
MC/DC0%0/1
$opts{"verbose"} //= 0
$opts{"verbose"}
Truth table0%0/2
A
A= $opts{"verbose"}
| |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $opts{timestamp} //= fs_time($self->{dir}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"timestamp"} //= fs_time($self->{"dir"})
MC/DC0%0/2
$opts{"timestamp"} //= fs_time($self->{"dir"})
$opts{"timestamp"}
fs_time($self->{"dir"})
Truth table0%0/3
A //= B
A= $opts{"timestamp"}B= fs_time($self->{"dir"})
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | my $patch = $self->next(); | |||||||||||||||||||||||||||
| 179 | 0 | ▶ | return unless defined $patch; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my $path = $self->get_patch_file($patch); | |||||||||||||||||||||||||||
| 182 | 0 | my $obj = Dpkg::Source::Patch->new(filename => $path); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | info(g_('applying %s'), $patch) if $opts{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | eval { | |||||||||||||||||||||||||||
| 186 | $obj->apply($self->{dir}, | ||||||||||||||||||||||||||||
| 187 | verbose => $opts{verbose}, | ||||||||||||||||||||||||||||
| 188 | timestamp => $opts{timestamp}, | ||||||||||||||||||||||||||||
| 189 | 0 | force_timestamp => 1, | |||||||||||||||||||||||||||
| 190 | create_dirs => 1, | ||||||||||||||||||||||||||||
| 191 | remove_backup => 0, | ||||||||||||||||||||||||||||
| 192 | options => [ | ||||||||||||||||||||||||||||
| 193 | '-t', | ||||||||||||||||||||||||||||
| 194 | '-F', '0', | ||||||||||||||||||||||||||||
| 195 | '-N', | ||||||||||||||||||||||||||||
| 196 | '-p1', | ||||||||||||||||||||||||||||
| 197 | '-u', | ||||||||||||||||||||||||||||
| 198 | '-V', 'never', | ||||||||||||||||||||||||||||
| 199 | '-E', | ||||||||||||||||||||||||||||
| 200 | '-b', | ||||||||||||||||||||||||||||
| 201 | '-B', ".pc/$patch/", | ||||||||||||||||||||||||||||
| 202 | '--reject-file=-', | ||||||||||||||||||||||||||||
| 203 | ], | ||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | info(g_('the patch has fuzz which is not allowed, or is malformed')); | |||||||||||||||||||||||||||
| 208 | 0 | info(g_("if patch '%s' is correctly applied by quilt, use '%s' to update it"), | |||||||||||||||||||||||||||
| 209 | $patch, 'quilt refresh'); | ||||||||||||||||||||||||||||
| 210 | 0 | info(g_('if the file is present in the unpacked source, make sure it ' . | |||||||||||||||||||||||||||
| 211 | 'is also present in the orig tarball')); | ||||||||||||||||||||||||||||
| 212 | 0 | $self->restore_quilt_backup_files($patch, %opts); | |||||||||||||||||||||||||||
| 213 | 0 | erasedir($self->get_db_file($patch)); | |||||||||||||||||||||||||||
| 214 | 0 | die $@; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 0 | CORE::push @{$self->{applied_patches}}, $patch; | |||||||||||||||||||||||||||
| 217 | 0 | $self->save_db(); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub pop { | ||||||||||||||||||||||||||
|
Subroutine
pop: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 221 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | $opts{verbose} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"verbose"} //= 0
MC/DC0%0/1
$opts{"verbose"} //= 0
$opts{"verbose"}
Truth table0%0/2
A
A= $opts{"verbose"}
| |||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $opts{timestamp} //= fs_time($self->{dir}); | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"timestamp"} //= fs_time($self->{"dir"})
MC/DC0%0/2
$opts{"timestamp"} //= fs_time($self->{"dir"})
$opts{"timestamp"}
fs_time($self->{"dir"})
Truth table0%0/3
A //= B
A= $opts{"timestamp"}B= fs_time($self->{"dir"})
| |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $opts{reverse_apply} //= 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"reverse_apply"} //= 0
MC/DC0%0/1
$opts{"reverse_apply"} //= 0
$opts{"reverse_apply"}
Truth table0%0/2
A
A= $opts{"reverse_apply"}
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | my $patch = $self->top(); | |||||||||||||||||||||||||||
| 227 | 0 | ▶ | return unless defined $patch; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | info(g_('unapplying %s'), $patch) if $opts{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | my $backup_dir = $self->get_db_file($patch); | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (-d $backup_dir and not $opts{reverse_apply}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $backup_dir and not $opts{"reverse_apply"}
MC/DC0%0/2
-d $backup_dir and not $opts{"reverse_apply"}
-d $backup_dir
not $opts{"reverse_apply"}
Truth table0%0/3
A and not(B)
A= -d $backup_dirB= not $opts{"reverse_apply"}
| |||||||||||||||||||||||||||||
| 232 | # Use the backup copies to restore. | ||||||||||||||||||||||||||||
| 233 | 0 | $self->restore_quilt_backup_files($patch); | |||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||
| 235 | # Otherwise reverse-apply the patch. | ||||||||||||||||||||||||||||
| 236 | 0 | my $path = $self->get_patch_file($patch); | |||||||||||||||||||||||||||
| 237 | 0 | my $obj = Dpkg::Source::Patch->new(filename => $path); | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | $obj->apply($self->{dir}, | ||||||||||||||||||||||||||||
| 240 | verbose => 0, | ||||||||||||||||||||||||||||
| 241 | timestamp => $opts{timestamp}, | ||||||||||||||||||||||||||||
| 242 | 0 | force_timestamp => 1, | |||||||||||||||||||||||||||
| 243 | remove_backup => 0, | ||||||||||||||||||||||||||||
| 244 | options => [ | ||||||||||||||||||||||||||||
| 245 | '-R', | ||||||||||||||||||||||||||||
| 246 | '-t', | ||||||||||||||||||||||||||||
| 247 | '-N', | ||||||||||||||||||||||||||||
| 248 | '-p1', | ||||||||||||||||||||||||||||
| 249 | '-u', | ||||||||||||||||||||||||||||
| 250 | '-V', 'never', | ||||||||||||||||||||||||||||
| 251 | '-E', | ||||||||||||||||||||||||||||
| 252 | '--no-backup-if-mismatch', | ||||||||||||||||||||||||||||
| 253 | ], | ||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | erasedir($backup_dir); | |||||||||||||||||||||||||||
| 258 | 0 | pop @{$self->{applied_patches}}; | |||||||||||||||||||||||||||
| 259 | 0 | $self->save_db(); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub get_db_version { | ||||||||||||||||||||||||||
|
Subroutine
get_db_version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 263 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 264 | 0 | my $pc_ver = $self->get_db_file('.version'); | |||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (-f $pc_ver) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 0 | my $version = file_slurp($pc_ver); | |||||||||||||||||||||||||||
| 267 | 0 | chomp $version; | |||||||||||||||||||||||||||
| 268 | 0 | return $version; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | 0 | return; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | sub find_problems { | ||||||||||||||||||||||||||
|
Subroutine
find_problems: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 274 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 275 | 0 | my $patch_dir = $self->get_patch_dir(); | |||||||||||||||||||||||||||
| 276 | 0 | ▶ | if (-e $patch_dir and not -d _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $patch_dir and not -d _
MC/DC0%0/2
-e $patch_dir and not -d _
-e $patch_dir
not -d _
Truth table0%0/3
A and not(B)
A= -e $patch_dirB= not -d _
| |||||||||||||||||||||||||||||
| 277 | 0 | return sprintf(g_('%s should be a directory or non-existing'), $patch_dir); | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | 0 | my $series = $self->get_series_file(); | |||||||||||||||||||||||||||
| 280 | 0 | ▶ | if (-e $series and not -f _) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $series and not -f _
MC/DC0%0/2
-e $series and not -f _
-e $series
not -f _
Truth table0%0/3
A and not(B)
A= -e $seriesB= not -f _
| |||||||||||||||||||||||||||||
| 281 | 0 | return sprintf(g_('%s should be a file or non-existing'), $series); | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | 0 | return; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 1 | ▶ | sub get_series_file { | ||||||||||||||||||||||||||
|
Subroutine
get_series_file: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 287 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 288 | 1 | ▶ | my $vendor = lc(get_current_vendor() || 'debian'); | ||||||||||||||||||||||||||
|
Condition50%1/2
get_current_vendor() || 'debian'
MC/DC0%0/1
get_current_vendor() || 'debian'
get_current_vendor()
Truth table50%1/2
A
A= get_current_vendor()
| |||||||||||||||||||||||||||||
| 289 | # Series files are stored alongside patches. | ||||||||||||||||||||||||||||
| 290 | 1 | my $default_series = $self->get_patch_file('series'); | |||||||||||||||||||||||||||
| 291 | 1 | my $vendor_series = $self->get_patch_file("$vendor.series"); | |||||||||||||||||||||||||||
| 292 | 1 | ▶ | return $vendor_series if -e $vendor_series; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 1 | return $default_series; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 1 | ▶ | sub get_db_file { | ||||||||||||||||||||||||||
|
Subroutine
get_db_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 297 | 1 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 1 | return File::Spec->catfile($self->get_db_dir(), $file); | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 1 | ▶ | sub get_db_dir { | ||||||||||||||||||||||||||
|
Subroutine
get_db_dir: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 303 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 1 | return File::Spec->catfile($self->{dir}, '.pc'); | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 2 | ▶ | sub get_patch_file { | ||||||||||||||||||||||||||
|
Subroutine
get_patch_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 309 | 2 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 2 | return File::Spec->catfile($self->get_patch_dir(), $file); | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 2 | ▶ | sub get_patch_dir { | ||||||||||||||||||||||||||
|
Subroutine
get_patch_dir: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 315 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 2 | return File::Spec->catfile($self->{dir}, 'debian', 'patches'); | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | ## Internal methods. | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub _file_load { | ||||||||||||||||||||||||||
|
Subroutine
_file_load: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 323 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | open my $file_fh, '<', $file or syserr(g_('cannot read %s'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 0 | my @lines = <$file_fh>; | |||||||||||||||||||||||||||
| 327 | 0 | close $file_fh; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | return @lines; | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | sub _file_add_line { | ||||||||||||||||||||||||||
|
Subroutine
_file_add_line: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 333 | 0 | my ($self, $file, $line) = @_; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | my @lines; | |||||||||||||||||||||||||||
| 336 | 0 | ▶ | @lines = $self->_file_load($file) if -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 0 | CORE::push @lines, $line; | |||||||||||||||||||||||||||
| 338 | 0 | chomp @lines; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | ▶ | open my $file_fh, '>', $file or syserr(g_('cannot write %s'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 0 | print { $file_fh } "$_\n" foreach @lines; | |||||||||||||||||||||||||||
| 342 | 0 | close $file_fh; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | sub _file_drop_line { | ||||||||||||||||||||||||||
|
Subroutine
_file_drop_line: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 346 | 0 | my ($self, $file, $re) = @_; | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | my @lines = $self->_file_load($file); | |||||||||||||||||||||||||||
| 349 | 0 | ▶ | open my $file_fh, '>', $file or syserr(g_('cannot write %s'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | print { $file_fh } $_ foreach grep { not /^\Q$re\E\s*$/ } @lines; | |||||||||||||||||||||||||||
| 351 | 0 | close $file_fh; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 2 | ▶ | sub read_patch_list { | ||||||||||||||||||||||||||
|
Subroutine
read_patch_list: called CC=11 SCAR=25.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 355 | 2 | my ($self, $file, %opts) = @_; | |||||||||||||||||||||||||||
| 356 | 2 | ▶ | return () if not defined $file or not -f $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $file and -f $file
MC/DC50%1/2
defined $file and -f $file
defined $file
-f $file
Truth table66%2/3
A and B
A= defined $fileB= -f $file
| |||||||||||||||||||||||||||||
| 357 | 1 | ▶ | $opts{warn_options} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"warn_options"} //= 0
MC/DC0%0/1
$opts{"warn_options"} //= 0
$opts{"warn_options"}
Truth table50%1/2
A
A= $opts{"warn_options"}
| |||||||||||||||||||||||||||||
| 358 | 1 | my @patches; | |||||||||||||||||||||||||||
| 359 | 1 | ▶ | open(my $series_fh, '<' , $file) or syserr(g_('cannot read %s'), $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 1 | ▶ | while (defined(my $line = <$series_fh>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | 9 | chomp $line; | |||||||||||||||||||||||||||
| 362 | # Strip leading/trailing spaces. | ||||||||||||||||||||||||||||
| 363 | 9 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||
| 364 | 9 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||
| 365 | # Strip comment. | ||||||||||||||||||||||||||||
| 366 | 9 | $line =~ s/(?:^|\s+)#.*$//; | |||||||||||||||||||||||||||
| 367 | 9 | ▶ | next unless $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 4 | ▶ | if ($line =~ /^(\S+)\s+(.*)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 2 | $line = $1; | |||||||||||||||||||||||||||
| 370 | 2 | ▶ | if ($2 ne '-p1') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | warning(g_('the series file (%s) contains unsupported ' . | ||||||||||||||||||||||||||||
| 372 | "options ('%s', line %s); dpkg-source might " . | ||||||||||||||||||||||||||||
| 373 | 'fail when applying patches'), | ||||||||||||||||||||||||||||
| 374 | 0 | ▶ | $file, $2, $.) if $opts{warn_options}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | 4 | ▶ | if ($line =~ m{(^|/)\.\./}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | error(g_('%s contains an insecure path: %s'), $file, $line); | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | 4 | CORE::push @patches, $line; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 1 | close($series_fh); | |||||||||||||||||||||||||||
| 383 | 1 | return @patches; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub write_patch_list { | ||||||||||||||||||||||||||
|
Subroutine
write_patch_list: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 387 | 0 | my ($self, $series, $patches) = @_; | |||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | 0 | ▶ | open my $series_fh, '>', $series or syserr(g_('cannot write %s'), $series); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 390 | 0 | foreach my $patch (@{$patches}) { | |||||||||||||||||||||||||||
| 391 | 0 | print { $series_fh } "$patch\n"; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 0 | close $series_fh; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | ▶ | sub restore_quilt_backup_files { | ||||||||||||||||||||||||||
|
Subroutine
restore_quilt_backup_files: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 397 | 0 | my ($self, $patch, %opts) = @_; | |||||||||||||||||||||||||||
| 398 | 0 | my $patch_dir = $self->get_db_file($patch); | |||||||||||||||||||||||||||
| 399 | 0 | ▶ | return unless -d $patch_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | info(g_('restoring quilt backup files for %s'), $patch) if $opts{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | my $scan_quilt = { | ||||||||||||||||||||||||||||
| 402 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 403 | 0 | ▶ | wanted => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 404 | 0 | ▶ | my $st = File::stat::stat($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 405 | or syserr(g_('cannot stat %s'), $_); | ||||||||||||||||||||||||||||
| 406 | 0 | ▶ | return if -d $st; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 0 | my $relpath_in_srcpkg = File::Spec->abs2rel($_, $patch_dir); | |||||||||||||||||||||||||||
| 408 | 0 | my $target = File::Spec->catfile($self->{dir}, $relpath_in_srcpkg); | |||||||||||||||||||||||||||
| 409 | 0 | ▶ | if (-s $st) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | 0 | unlink($target); | |||||||||||||||||||||||||||
| 411 | 0 | make_path(dirname($target)); | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | unless (link($_, $target)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | copy($_, $target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | or syserr(g_('cannot copy %s to %s'), $_, $target); | ||||||||||||||||||||||||||||
| 415 | 0 | ▶ | chmod_if_needed(S_IMODE($st->mode), $target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | or syserr(g_("cannot change permission of '%s'"), $target); | ||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | } else { | ||||||||||||||||||||||||||||
| 419 | # Empty files are "backups" for new files that patch created. | ||||||||||||||||||||||||||||
| 420 | 0 | unlink($target); | |||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | }, | ||||||||||||||||||||||||||||
| 423 | 0 | }; | |||||||||||||||||||||||||||
| 424 | 0 | find($scan_quilt, $patch_dir); | |||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =head1 CHANGES | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =head2 Version 0.xx | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | This is a private module. | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | =cut | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 1 | 1; | |||||||||||||||||||||||||||