]> git.proxmox.com Git - dab.git/commitdiff
constructor: factor out getting the target name
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 21 Oct 2022 11:55:38 +0000 (13:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 21 Oct 2022 12:20:31 +0000 (14:20 +0200)
get_target_name will be reused later for adding a dab command to get
the final archive name, to be used for a `make upload` target.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
DAB.pm

diff --git a/DAB.pm b/DAB.pm
index 57ea2ecfb3df4ba97b9ad91c18abb9e32855ae51..b85d0a60a87ec7373a8c008c35573142f621cdb4 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -521,6 +521,18 @@ sub setup_usr_merge {
     }
 }
 
+sub get_target_name {
+    my ($config) = @_;
+
+    my $name = $config->{name} || die "no 'name' specified\n";
+    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
+
+    my ($version, $arch, $ostype) = $config->@{'version', 'architecture', 'ostype'};
+    $name = "${ostype}-${name}" if $name !~ m/^$ostype/;
+
+    return "${name}_${version}_${arch}"
+}
+
 sub new {
     my ($class, $config) = @_;
 
@@ -535,7 +547,7 @@ sub new {
     $self->{logfile} = "logfile";
     $self->{logfd} = IO::File->new (">>$self->{logfile}") || die "unable to open log file";
 
-    my $arch = $config->{architecture} ||die "no 'architecture' specified\n";
+    my $arch = $config->{architecture} || die "no 'architecture' specified\n";
     die "unsupported architecture '$arch'\n" if $arch !~ m/^(i386|amd64)$/;
 
     my $suite = $config->{suite} || die "no 'suite' specified\n";
@@ -544,20 +556,12 @@ sub new {
     $suite = $suiteinfo->{suite};
     $config->{ostype} = $suiteinfo->{ostype};
 
-    my $name = $config->{name} || die "no 'name' specified\n";
-    $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
-
     # assert required dab.conf keys exist
     for my $key (qw(version section headline maintainer)) {
        die "no '$key' specified\n" if !$config->{$key};
     }
-    my $version = $config->{version};
 
-    if ($name =~ m/^$config->{ostype}/) {
-       $self->{targetname} = "${name}_${version}_$config->{architecture}";
-    } else {
-       $self->{targetname} = "$config->{ostype}-${name}_${version}_$config->{architecture}";
-    }
+    $self->{targetname} = get_target_name($config);
 
     if (!$config->{source}) {
        if (lc($suiteinfo->{origin}) eq 'debian') {