summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-03-29 15:15:35 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-03-29 15:15:35 (GMT)
commit3ac0a7b9a2b31b98700ee3199db6feda7f08454d (patch) (side-by-side diff)
tree4fa3e44c32e68be29e7b534943c149ed34c2d3ac
parent14099edd51d7d651e315670c1dab493423ed3e2a (diff)
downloadslackbuilder-3ac0a7b9a2b31b98700ee3199db6feda7f08454d.tar.gz
slackbuilder-3ac0a7b9a2b31b98700ee3199db6feda7f08454d.tar.bz2
Redo logfile support.
* lib/SlackBuild/Registry/Record.pm (split): New class method. * lib/SlackBuild/Registry/Backend/FS.pm (scan): Use SlackBuild::Registry::Record->split. * t/regrec.t: Test SlackBuild::Registry::Record->split. * lib/SlackBuild/Request.pm (merge): New method (for future use). Introduce default attribute values. Set default for build to 1. * lib/SlackBuild/URI.pm (download): Bugfix. Pass one argument to $result->content_type. * lib/SlackBuilder.pm: Create log as a temporary file. Rename it to its final name after the build has finished. This is necessary because at the initial stage the request might lack some of the parameters needed to construct the log file name.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/SlackBuild/Registry/Backend/FS.pm23
-rw-r--r--lib/SlackBuild/Registry/Record.pm28
-rw-r--r--lib/SlackBuild/Request.pm15
-rw-r--r--lib/SlackBuild/URI.pm2
-rw-r--r--lib/SlackBuilder.pm59
-rw-r--r--t/regrec.t10
6 files changed, 104 insertions, 33 deletions
diff --git a/lib/SlackBuild/Registry/Backend/FS.pm b/lib/SlackBuild/Registry/Backend/FS.pm
index d7d6918..61cbe7d 100644
--- a/lib/SlackBuild/Registry/Backend/FS.pm
+++ b/lib/SlackBuild/Registry/Backend/FS.pm
@@ -3,7 +3,6 @@ use strict;
use warnings;
use Carp;
use File::Basename;
-use List::Regexp;
use File::stat;
use File::Spec;
use Fcntl ':mode';
@@ -42,18 +41,12 @@ sub new {
return $self;
}
-my @architectures = qw(i386 x86_64 arm noarch);
my @suffixes = qw(.tgz .txz);
sub scan {
my $self = shift;
my $pat = "*-*-*-*";
- my $rx = '^(?<pkg>.+)-'
- . '(?<vpfx>.*?)'
- . '(?<version>\d+(?:\.\d+)*.*?)'
- . '-(?<arch>' . regexp_opt(@architectures) . ')'
- . '-(?<build>\d+)(?<rest>[[:punct:]].*)?$';
$self->{ls} = [sort {
my $d;
if ($d = ($a->package || '') cmp ($b->package || '')) {
@@ -69,21 +62,17 @@ sub scan {
}
map {
my ($name,$path,$suffix) = fileparse($_, @suffixes);
- if ($name =~ m{$rx}) {
+ my $rec = SlackBuild::Registry::Record->split($name);
+ if ($rec) {
my $st = stat($_);
if (S_ISREG($st->mode)) {
- new SlackBuild::Registry::Record($+{pkg},
- version => $+{version},
- arch => $+{arch},
- build => $+{build},
- date => $st->mtime,
- filename => File::Spec->abs2rel($_, $self->{dir}))
+ $rec->date($st->mtime);
+ $rec->filename(File::Spec->abs2rel($_, $self->{dir}));
} else {
- ()
+ $rec = undef;
}
- } else {
- ()
}
+ $rec
} (glob File::Spec->catfile($self->{dir}, $pat))];
$self->{index}{$self->{ls}[0]->package}[0] = 0;
diff --git a/lib/SlackBuild/Registry/Record.pm b/lib/SlackBuild/Registry/Record.pm
index 3af5f96..81a705c 100644
--- a/lib/SlackBuild/Registry/Record.pm
+++ b/lib/SlackBuild/Registry/Record.pm
@@ -5,6 +5,8 @@ use Carp;
use SlackBuild::Base qw(package arch build date filename);
use SlackBuild::Registry::Version;
use Scalar::Util qw(blessed);
+use List::Regexp;
+use File::Basename;
=head2 new
@@ -30,6 +32,32 @@ sub new {
return $self;
}
+my @architectures = qw(i386 x86_64 arm noarch);
+
+my $rx = '^(?<pkg>.+)-'
+ . '(?<vpfx>.*?)'
+ . '(?<version>\d+(?:\.\d+)*.*?)'
+ . '-(?<arch>' . regexp_opt(@architectures) . ')'
+ . '-(?<build>\d+)(?<rest>[[:punct:]].*)?$';
+
+=head2 split
+
+ $r = SlackBuild::Registry::Record->split($filename, %opt)
+
+=cut
+
+sub split {
+ my ($class, $filename, %opt) = @_;
+ if (basename($filename) =~ m{$rx}) {
+ return $class->new($+{pkg},
+ version => $+{version},
+ arch => $+{arch},
+ build => $+{build},
+ filename => $filename,
+ %opt);
+ }
+}
+
sub version {
my $self = shift;
if (@_) {
diff --git a/lib/SlackBuild/Request.pm b/lib/SlackBuild/Request.pm
index 4ae81d3..3876b56 100644
--- a/lib/SlackBuild/Request.pm
+++ b/lib/SlackBuild/Request.pm
@@ -107,6 +107,7 @@ my %attributes = (
},
build => {
type => 'SCALAR',
+ default => 1,
},
slackbuild_uri => {
type => 'SCALAR',
@@ -163,7 +164,7 @@ my %generics = (
},
set => sub {
my ($self, $attr, $value, $strat) = @_;
- croak "hashref expected" unless ref($value) eq 'HASH';
+ croak "hashref expected when setting $attr" unless ref($value) eq 'HASH';
if (defined($self->{$attr}) && defined($strat)
&& $strat ne 'keep') {
if ($strat eq 'merge') {
@@ -349,6 +350,15 @@ sub load {
croak "unrecognized request type";
}
+sub merge {
+ my ($self, $other) = @_;
+ foreach my $attr (keys %attributes) {
+ unless (defined($self->{$attr})) {
+ $self->${\ "set_$attr"}($other->${\ $attr});
+ }
+ }
+}
+
=head1 STRING REPRESENTATION
When used is string context, objects of this class are represented as
@@ -450,7 +460,8 @@ sub set_prereq {
unless (__PACKAGE__->can($attr)) {
*{ __PACKAGE__ . '::' . $attr } = sub {
my $self = shift;
- return $self->${ \ $generics{$descr->{type}}{get} }($attr);
+ return $self->${ \ $generics{$descr->{type}}{get} }($attr)
+ || $descr->{default};
}
}
unless (__PACKAGE__->can("set_$attr")) {
diff --git a/lib/SlackBuild/URI.pm b/lib/SlackBuild/URI.pm
index 91b10c2..b0d6724 100644
--- a/lib/SlackBuild/URI.pm
+++ b/lib/SlackBuild/URI.pm
@@ -77,7 +77,7 @@ sub download {
my $result = new SlackBuild::Download($self,
success => $response->is_success);
if ($response->is_success) {
- $result->content_type($response->content_type);
+ $result->content_type(scalar($response->content_type));
} else {
$self->logger->error("$self: " . $response->status_line);
}
diff --git a/lib/SlackBuilder.pm b/lib/SlackBuilder.pm
index bf792bf..6c0504d 100644
--- a/lib/SlackBuilder.pm
+++ b/lib/SlackBuilder.pm
@@ -6,6 +6,7 @@ use SlackBuild::Config;
use SlackBuild::URI;
use SlackBuild::Archive;
use SlackBuild::Registry;
+use SlackBuild::Registry::Record;
use SlackBuild::Request;
use SlackBuild::Rc;
use SlackBuild::Counter;
@@ -336,11 +337,6 @@ sub _runcap_diag {
}
$self->errno(E_EXEC);
}
-
-sub _logfilename {
- my $self = shift;
- return File::Spec->catfile($self->logdir, $self->package_name . '.log');
-}
sub _prepare {
my $self = shift;
@@ -487,6 +483,40 @@ sub parser_err {
$self->${\$parser_err[$self->state]}($line);
}
+sub commit_log {
+ my ($self, $logfd) = @_;
+ my $init;
+ my @v = map {
+ my $r = SlackBuild::Registry::Record->split($_);
+ if ($r && (!$init || $r->package eq $self->package_name)) {
+ $init = 1;
+ $r
+ }
+ } $self->output_files;
+ my $r;
+ if (@v) {
+ $r = pop(@v);
+ } else {
+ $r = SlackBuild::Registry::Record->new(
+ $self->package_name,
+ version => $self->package_version || 'UNKNOWN',
+ build => $self->package_build,
+ arch => $self->arch);
+ }
+ my $logname = File::Spec->catfile($self->logdir, $r . '.log');
+ unless (rename $logfd->filename, $logname) {
+ $self->logger->error("can't rename "
+ . $logfd->filename
+ . " to "
+ . $logname
+ . ": $!");
+ $logname = $logfd->filename;
+ }
+ chmod 0666 & ~ umask(), $logname
+ or $self->logger->error("can't change file mode of $logname: $!");
+ $self->logger->info("Log file: $logname");
+}
+
sub _build {
my $self = shift;
@@ -512,13 +542,16 @@ sub _build {
$self->os_release('VERSION'),
$self->arch));
- open(my $logfd, '>', $self->_logfilename)
- or do {
- $self->logger->fatal("can't create log file " .
- $self->_logfilename .
- ": $!");
- return $self->errno(E_FAIL);
+ my $logfd = try {
+ File::Temp->new(UNLINK => 0,
+ TEMPLATE => $self->package_name . ".XXXXXX",
+ DIR => $self->logdir,
+ SUFFIX => '.log');
+ } catch {
+ $self->logger->fatal("can't create log file: ". (split /\n/)[0]);
+ undef;
};
+ return $self->errno(E_FAIL) unless $logfd;
$self->state(ST_INIT);
my $obj = new POSIX::Run::Capture(
@@ -541,9 +574,13 @@ sub _build {
if ($obj->run) {
$self->_runcap_diag($obj);
} else {
+ $self->commit_log($logfd);
$self->logger->fatal("can't run docker: ".strerror($obj->errno));
return $self->errno(E_EXEC);
}
+
+ $self->commit_log($logfd);
+
return $self->errno(E_OK);
}
diff --git a/t/regrec.t b/t/regrec.t
index 516480a..1ab168a 100644
--- a/t/regrec.t
+++ b/t/regrec.t
@@ -6,7 +6,7 @@ use SlackBuild::Registry::Record;
use SlackBuild::Registry::Pattern;
use Test;
-plan tests => 7;
+plan tests => 12;
my $r = new SlackBuild::Registry::Record('foo',
arch => 'x86_64',
@@ -40,4 +40,10 @@ my $pat = new SlackBuild::Registry::Pattern(
ok($pat->as_string,
q{[{"package":{"-eq":"bar"}},{"version":{"-eq":"1.1"}},{"arch":{"-in":["noarch","x86_64"]}},{"build":{"-eq":2}}]});
-print $pat->package,"\n";
+$r = SlackBuild::Registry::Record->split('foo-1.0-x86_64-2');
+ok($r);
+ok($r->package, 'foo');
+ok($r->version, '1.0');
+ok($r->arch, 'x86_64');
+ok($r->build, 2);
+

Return to:

Send suggestions and report system problems to the System administrator.