summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2015-03-13 23:59:55 +0100
committerGuillem Jover <guillem@debian.org>2015-05-09 06:19:40 +0200
commitab15fd24dd1a8207ab1463410338f24283989f7c (patch)
tree1dbdb0df5ced829a7c084068f4ecd9b9f16e90e5
parent715a507fc59c7cf679c7fedcd8f336697893ed27 (diff)
downloaddpkg-ab15fd24dd1a8207ab1463410338f24283989f7c.tar.gz
Dpkg::Dist::Files: Parse filename on add_file() to initialize files values
-rw-r--r--scripts/Dpkg/Dist/Files.pm15
-rw-r--r--scripts/t/Dpkg_Dist_Files.t16
2 files changed, 21 insertions, 10 deletions
diff --git a/scripts/Dpkg/Dist/Files.pm b/scripts/Dpkg/Dist/Files.pm
index 3860f4c3d..dc9e05dfb 100644
--- a/scripts/Dpkg/Dist/Files.pm
+++ b/scripts/Dpkg/Dist/Files.pm
@@ -110,15 +110,12 @@ sub get_file {
sub add_file {
my ($self, $filename, $section, $priority) = @_;
- # XXX: Ideally we'd need to parse the filename, to match the behaviour
- # on parse(), and initialize the other attributes, although no code is
- # in need of this for now, at least in dpkg-dev.
-
- $self->{files}->{$filename} = {
- filename => $filename,
- section => $section,
- priority => $priority,
- };
+ my $file = $self->parse_filename($filename);
+ error(g_('invalid filename %s'), $filename) unless defined $file;
+ $file->{section} = $section;
+ $file->{priority} = $priority;
+
+ $self->{files}->{$filename} = $file;
}
sub del_file {
diff --git a/scripts/t/Dpkg_Dist_Files.t b/scripts/t/Dpkg_Dist_Files.t
index 019bbe773..770c3fead 100644
--- a/scripts/t/Dpkg_Dist_Files.t
+++ b/scripts/t/Dpkg_Dist_Files.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 15;
+use Test::More tests => 17;
use_ok('Dpkg::Dist::Files');
@@ -62,6 +62,11 @@ my %expected = (
section => 'webdocs',
priority => 'optional',
},
+ 'added-on-the-fly' => {
+ filename => 'added-on-the-fly',
+ section => 'void',
+ priority => 'wish',
+ },
);
my $dist = Dpkg::Dist::Files->new();
@@ -96,7 +101,16 @@ pkg-templ_1.2.3_arch.type section priority
FILES
$dist->add_file('added-on-the-fly', 'void', 'wish');
+is_deeply($dist->get_file('added-on-the-fly'), $expected{'added-on-the-fly'},
+ 'Get added file added-on-the-fly');
+
$dist->add_file('pkg-arch_2.0.0_amd64.deb', 'void', 'imperative');
+my %expected_pkg_arch = %{$expected{'pkg-arch_2.0.0_amd64.deb'}};
+$expected_pkg_arch{section} = 'void';
+$expected_pkg_arch{priority} = 'imperative';
+is_deeply($dist->get_file('pkg-arch_2.0.0_amd64.deb'), \%expected_pkg_arch,
+ 'Get modified file pkg-arch_2.0.0_amd64.deb');
+
$dist->del_file('pkg-indep_0.0.1-2_all.deb');
is($dist->get_file('unknown'), undef, 'Get unknown file');
is($dist->get_file('pkg-indep_0.0.1-2_all.deb'), undef, 'Get deleted file');