Skip to content

Commit

Permalink
[backend] refactor local source access methods into BSSrcServer::Local
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Sep 9, 2016
1 parent bcb1bfb commit 5c66fee
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 46 deletions.
23 changes: 9 additions & 14 deletions src/backend/BSSrcServer/Link.pm
Expand Up @@ -28,25 +28,20 @@ use BSUtil;
use BSVerify;

use BSSrcServer::Access;
use BSSrcServer::Local;

my $srcrep = "$BSConfig::bsdir/sources";
my $uploaddir = "$srcrep/:upload";


# this is what's used to get the next hop
our $getrev = sub {
my ($projid, $packid, $revid, $linked, $missingok) = @_;
my $rev = BSRevision::getrev_local($projid, $packid, $revid);
return $rev if $rev;
return {'project' => $projid, 'package' => $packid, 'srcmd5' => $BSSrcrep::emptysrcmd5} if $missingok;
die("404 package '$packid' does not exist in project '$projid'\n");
};

our $lsrev = sub {
our $getrev = \&BSSrcServer::Local::getrev;

our $lsrev_linktarget = sub {
return BSSrcrep::lsrev($_[0], $_[1] || {})
};


my $srcrep = "$BSConfig::bsdir/sources";
my $uploaddir = "$srcrep/:upload";

sub isascii {
my ($file) = @_;
return 0 if $file =~ /\.obscpio$/;
Expand Down Expand Up @@ -597,7 +592,7 @@ sub handlelinks {
undef $files;
eval {
# links point to expanded services
$files = $lsrev->($lrev);
$files = $lsrev_linktarget->($lrev);
};
if ($@) {
my $error = $@;
Expand Down Expand Up @@ -1064,7 +1059,7 @@ sub findlastworkinglink {

sub lsrev_expanded {
my ($rev, $linkinfo) = @_;
my $files = $lsrev->($rev, $linkinfo);
my $files = $lsrev_linktarget->($rev, $linkinfo);
return $files unless $files->{'_link'};
$files = handlelinks($rev, $files, $linkinfo);
die("$files\n") unless ref $files;
Expand Down
64 changes: 64 additions & 0 deletions src/backend/BSSrcServer/Local.pm
@@ -0,0 +1,64 @@
# Copyright (c) 2016 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#

package BSSrcServer::Local;

use strict;
use warnings;

use BSRevision;

sub getrev {
my ($projid, $packid, $revid, $linked, $missingok) = @_;
my $rev = BSRevision::getrev_local($projid, $packid, $revid);
return $rev if $rev;
return {'project' => $projid, 'package' => $packid, 'srcmd5' => $BSSrcrep::emptysrcmd5} if $missingok;
die("404 package '$packid' does not exist in project '$projid'\n");
}

sub findprojects {
my ($deleted) = @_;
return BSRevision::lsprojects_local($deleted);
}

sub findpackages {
my ($projid, $proj, $nonfatal, $origins, $noexpand, $deleted) = @_;
my @packids = BSRevision::lspackages_local($projid, $deleted);
if ($origins) {
for (@packids) {
$origins->{$_} = $projid unless defined $origins->{$_};
}
}
}

sub readproject {
my ($projid, $proj, $revid, $missingok) = @_;
$proj ||= BSRevision::readproj_local($projid, 1, $revid);
$proj->{'name'} ||= $projid if $proj;
die("404 project '$projid' does not exist\n") if !$missingok && !$proj;
return $proj;
}

sub readpackage {
my ($projid, $proj, $packid, $revid, $missingok) = @_;
my $pack = BSRevision::readpack_local($projid, $packid, 1, $revid);
$pack->{'project'} ||= $projid if $pack;
die("404 package '$packid' does not exist in project '$projid'\n") if !$missingok && !$pack;
return $pack;
}

1;
40 changes: 14 additions & 26 deletions src/backend/BSSrcServer/Projlink.pm
Expand Up @@ -23,35 +23,15 @@ use BSRevision;
use BSSrcrep;
use BSAccess;

our $frozenlinks_cache;
use BSSrcServer::Local;

#############################################################################
my $frozenlinks_cache;

our $getrev = sub {
my ($projid, $packid, $revid, $linked, $missingok) = @_;
my $rev = BSRevision::getrev_local($projid, $packid, $revid);
return $rev if $rev;
return {'project' => $projid, 'package' => $packid, 'srcmd5' => $BSSrcrep::emptysrcmd5} if $missingok;
die("404 package '$packid' does not exist in project '$projid'\n");
};

our $findpackages = sub {
my ($projid, $proj, $nonfatal, $origins, $noexpand, $deleted) = @_;
my @packids = BSRevision::lspackages_local($projid, $deleted);
if ($origins) {
for (@packids) {
$origins->{$_} = $projid unless defined $origins->{$_};
}
}
};
#############################################################################

our $readpackage = sub {
my ($projid, $proj, $packid, $revid, $missingok) = @_;
my $pack = BSRevision::readpack_local($projid, $packid, 1);
$pack->{'project'} ||= $projid if $pack;
die("404 package '$packid' does not exist in project '$projid'\n") if !$missingok && !$pack;
return $pack;
};
our $getrev = \&BSSrcServer::Local::getrev;
our $findpackages = \&BSSrcServer::Local::findpackages;
our $readpackage = \&BSSrcServer::Local::readpackage;

#############################################################################

Expand Down Expand Up @@ -180,4 +160,12 @@ sub readpackage_projlink {
return undef;
}

sub enable_frozenlinks_cache {
$frozenlinks_cache ||= {};
}

sub disable_frozenlinks_cache {
$frozenlinks_cache = undef;
}

1;
13 changes: 7 additions & 6 deletions src/backend/bs_srcserver
Expand Up @@ -79,7 +79,7 @@ $BSSrcServer::Projlink::readpackage = \&readpackage;

# links point to service expanded files
$BSSrcServer::Link::getrev = \&getrev;
$BSSrcServer::Link::lsrev = \&lsrev_service;
$BSSrcServer::Link::lsrev_linktarget = \&lsrev_service;

$BSSrcServer::Service::getrev = \&getrev;
$BSSrcServer::Service::readpackage = \&readpackage;
Expand Down Expand Up @@ -983,7 +983,7 @@ sub getprojpack {
$packids = { map {$_ => 1} @$packids } if $packids;
my $bconf = Build::read_config($arch);

$BSSrcServer::Projlink::frozenlinks_cache = {};
BSSrcServer::Projlink::enable_frozenlinks_cache();
my %channeldata;
my @res;
my @projids = @$projids;
Expand Down Expand Up @@ -1595,7 +1595,8 @@ sub getprojpack {
$jinfo->{'package'} = \@pinfo;
push @res, $jinfo;
}
$BSSrcServer::Projlink::frozenlinks_cache = undef;
BSSrcServer::Projlink::disable_frozenlinks_cache();

my $ret = {'repoid' => $datarepoid, 'project' => \@res};
if ($remotemap) {
delete $remotemap->{':partition'};
Expand Down Expand Up @@ -1635,7 +1636,7 @@ sub getprojectlist {

sub getproject {
my ($cgi, $projid) = @_;
$proj = readproject($projid, undef, $cgi->{'rev'});
my $proj = readproject($projid, undef, $cgi->{'rev'});
return ($proj, $BSXML::proj);
}

Expand Down Expand Up @@ -5298,7 +5299,7 @@ sub getprojectsourceinfo {
my ($cgi, $projid) = @_;
my $proj = checkprojrepoarch($projid, $cgi->{'repository'}, $cgi->{'arch'}, 1);
my @packages = @{$cgi->{'package'} || []};
$BSSrcServer::Projlink::frozenlinks_cache = {};
BSSrcServer::Projlink::enable_frozenlinks_cache();
@packages = findpackages($projid, $proj) unless @packages;
my $bconf;
if (!$cgi->{'nofilename'}) {
Expand Down Expand Up @@ -5329,7 +5330,7 @@ sub getprojectsourceinfo {
for my $packid (@packages) {
push @res, sourceinfo($cgi, $projid, $packid, $bconf);
}
$BSSrcServer::Projlink::frozenlinks_cache = undef;
BSSrcServer::Projlink::disable_frozenlinks_cache();
return ({'sourceinfo' => \@res}, $BSXML::sourceinfolist);
}

Expand Down

0 comments on commit 5c66fee

Please sign in to comment.