1 # Copyright © 2014-2015 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
20 Dpkg::Dist::Files - handle built artifacts to distribute
24 This module provides a class used to parse and write the F<debian/files>
25 file, as part of the list of built artifacts to include in an upload.
27 B<Note>: This is a private module, its API can change at any time.
31 package Dpkg
::Dist
::Files
0.01;
39 use Dpkg
::ErrorHandling
;
41 use parent
qw(Dpkg::Interface::Storable);
44 my ($this, %opts) = @_;
45 my $class = ref($this) || $this;
51 foreach my $opt (keys %opts) {
52 $self->{$opt} = $opts{$opt};
70 if ($fn =~ m/^(([-+:.0-9a-z]+)_([^_]+)_([-\w]+)\.([a-z0-9.]+))$/) {
71 # Artifact using the common <name>_<version>_<arch>.<type> pattern.
72 $file->{filename
} = $1;
73 $file->{package} = $2;
74 $file->{version
} = $3;
76 $file->{package_type
} = $5;
77 } elsif ($fn =~ m/^([-+:.,_0-9a-zA-Z~]+)$/) {
78 # Artifact with no common pattern, usually called byhand or raw, as
79 # they might require manual processing on the server side, or custom
80 # actions per file type.
81 $file->{filename
} = $1;
90 my ($self, $fh, $desc) = @_;
101 if (m/^(\S+) (\S+) (\S+)((?:\s+[0-9a-z-]+=\S+)*)$/) {
102 $file = $self->parse_filename($1);
103 error
(g_
('badly formed file name in files list file, line %d'), $.)
104 unless defined $file;
105 $file->{section
} = $2;
106 $file->{priority
} = $3;
108 $file->{attrs
} = { map { split /=/ } split ' ', $attrs };
110 error
(g_
('badly formed line in files list file, line %d'), $.);
113 if (defined $self->{files
}->{$file->{filename
}}) {
114 warning
(g_
('duplicate files list entry for file %s (line %d)'),
115 $file->{filename
}, $.);
118 $self->{files
}->{$file->{filename
}} = $file;
126 my ($self, $dir) = @_;
129 my $dh = IO
::Dir
->new($dir) or syserr
(g_
('cannot open directory %s'), $dir);
131 while (defined(my $file = $dh->read)) {
132 my $pathname = "$dir/$file";
133 next unless -f
$pathname;
134 $count += $self->load($pathname);
143 return map { $self->{files
}->{$_} } sort keys %{$self->{files
}};
147 my ($self, $filename) = @_;
149 return $self->{files
}->{$filename};
153 my ($self, $filename, $section, $priority, %attrs) = @_;
155 my $file = $self->parse_filename($filename);
156 error
(g_
('invalid filename %s'), $filename) unless defined $file;
157 $file->{section
} = $section;
158 $file->{priority
} = $priority;
159 $file->{attrs
} = \
%attrs;
161 $self->{files
}->{$filename} = $file;
167 my ($self, $filename) = @_;
169 delete $self->{files
}->{$filename};
173 my ($self, %opts) = @_;
174 my $remove = $opts{remove
} // sub { 0 };
175 my $keep = $opts{keep
} // sub { 1 };
177 foreach my $filename (keys %{$self->{files
}}) {
178 my $file = $self->{files
}->{$filename};
180 if (not $keep->($file) or $remove->($file)) {
181 delete $self->{files
}->{$filename};
187 my ($self, $fh) = @_;
190 binmode $fh if defined $fh;
192 foreach my $filename (sort keys %{$self->{files
}}) {
193 my $file = $self->{files
}->{$filename};
194 my $entry = "$filename $file->{section} $file->{priority}";
196 if (exists $file->{attrs
}) {
197 foreach my $attr (sort keys %{$file->{attrs
}}) {
198 $entry .= " $attr=$file->{attrs}->{$attr}";
204 print { $fh } $entry if defined $fh;
215 This is a private module.