Skip to content

Commit

Permalink
[backend] Move lsrev and rep... functions from BSSrcrep to BSRevision
Browse files Browse the repository at this point in the history
They work with a revision, so they are more natural in BSRevision.
The BSSrcrep functions now take a projid/packid as args instead
of a revision (and are renamed to file...). There also is
lsfiles() now.
  • Loading branch information
mlschroe committed Sep 9, 2016
1 parent 5c66fee commit 0f9603c
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 192 deletions.
85 changes: 67 additions & 18 deletions src/backend/BSRevision.pm
Expand Up @@ -90,7 +90,7 @@ sub getrev_local {
return undef unless -e "$projectsdir/$projid.pkg/$packid.rev" || -e "$projectsdir/$projid.pkg/$packid.mrev";
$rev = {'srcmd5' => $revid, 'rev' => $revid};
} elsif ($revid eq 'upload') {
$rev = {'srcmd5' => 'upload', 'rev' => 'upload', 'special_meta' => "$projectsdir/$projid.pkg/$packid.upload-MD5SUMS"};
$rev = {'srcmd5' => 'upload', 'rev' => 'upload'};
} elsif ($revid eq 'repository') {
$rev = {'srcmd5' => $BSSrcrep::emptysrcmd5, 'rev' => 'repository'}
} elsif ($revid eq '0') {
Expand Down Expand Up @@ -187,35 +187,35 @@ sub retrofit_old_meta {

sub extract_old_prjsource {
my ($projid, $rev) = @_;
my $files = BSSrcrep::lsrev($rev);
my $files = lsrev($rev);
my $config;
$config = BSSrcrep::repreadstr($rev, '_config', $files->{'_config'}, 1) if $files->{'_config'};
$config = revreadstr($rev, '_config', $files->{'_config'}, 1) if $files->{'_config'};
writestr("$uploaddir/$$.2", "$projectsdir/$projid.conf", $config) if $config;
}

sub extract_old_meta {
my ($projid, $packid, $rev) = @_;
$rev->{'keepsignkey'} = 1;
my $files = BSSrcrep::lsrev($rev);
my $files = lsrev($rev);
delete $rev->{'keepsignkey'};
if (!defined($packid) || $packid eq '_project') {
$packid = '_project';
my $pubkey;
$pubkey = BSSrcrep::repreadstr($rev, '_pubkey', $files->{'_pubkey'}, 1) if $files->{'_pubkey'};
$pubkey = revreadstr($rev, '_pubkey', $files->{'_pubkey'}, 1) if $files->{'_pubkey'};
writestr("$uploaddir/$$.2", "$projectsdir/$projid.pkg/_pubkey", $pubkey) if $pubkey;
my $signkey;
$signkey = BSSrcrep::repreadstr($rev, '_signkey', $files->{'_signkey'}, 1) if $files->{'_signkey'};
$signkey = revreadstr($rev, '_signkey', $files->{'_signkey'}, 1) if $files->{'_signkey'};
if ($signkey) {
writestr("$uploaddir/$$.2", undef, $signkey);
chmod(0600, "$uploaddir/$$.2");
rename("$uploaddir/$$.2", "$projectsdir/$projid.pkg/_signkey") || die("rename $uploaddir/$$.2 $projectsdir/$projid.pkg/_signkey: $!\n");
}
my $meta;
$meta = BSSrcrep::repreadstr($rev, '_meta', $files->{'_meta'}, 1) if $files->{'_meta'};
$meta = revreadstr($rev, '_meta', $files->{'_meta'}, 1) if $files->{'_meta'};
writestr("$uploaddir/$$.2", "$projectsdir/$projid.xml", $meta) if $meta;
} else {
my $meta;
$meta = BSSrcrep::repreadstr($rev, '_meta', $files->{'_meta'}, 1) if $files->{'_meta'};
$meta = revreadstr($rev, '_meta', $files->{'_meta'}, 1) if $files->{'_meta'};
writestr("$uploaddir/$$.2", "$projectsdir/$projid.pkg/$packid.xml", $meta) if $meta;
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ sub addrev_replace_common {
$rev->{'project'} = $projid;
$rev->{'package'} = $rpackid;
$rev->{'keepsignkey'} = 1;
$files = BSSrcrep::lsrev($rev);
$files = lsrev($rev);
delete $rev->{'keepsignkey'};
} else {
$files = {};
Expand Down Expand Up @@ -320,7 +320,7 @@ sub updatelinkinfodb {
my $linkdb = BSDB::opendb($sourcedb, 'linkinfo');
my $linkinfo;
if ($files && $files->{'_link'}) {
my $l = BSSrcrep::repreadxml($rev, '_link', $files->{'_link'}, $BSXML::link, 1);
my $l = revreadxml($rev, '_link', $files->{'_link'}, $BSXML::link, 1);
if ($l) {
$linkinfo = {};
$linkinfo->{'project'} = defined $l->{'project'} ? $l->{'project'} : $projid;
Expand All @@ -342,7 +342,7 @@ sub movelinkinfos {
next unless -e "$projectsdir/$projid.pkg/$packid.xml";
eval {
my $rev = getrev_local($projid, $packid);
updatelinkinfodb($projid, $packid, $rev, BSSrcrep::lsrev($rev)) if $rev;
updatelinkinfodb($projid, $packid, $rev, lsrev($rev)) if $rev;
};
warn($@) if $@;
updatelinkinfodb($oprojid, $packid);
Expand Down Expand Up @@ -370,7 +370,7 @@ sub addrev_local {
$rev->{'project'} = $projid;
$rev->{'package'} = $packid;
if (!$files && !$cgi->{'nolinkinfodb'}) {
eval { $files = BSSrcrep::lsrev($rev) };
eval { $files = lsrev($rev) };
}
# update linked package database
updatelinkinfodb($projid, $packid, $rev, $files) if $files;
Expand Down Expand Up @@ -419,7 +419,7 @@ sub undelete_rev {
if ($packid eq '_project') {
extract_old_prjsource($projid, $nrev);
} else {
updatelinkinfodb($projid, $packid, $rev, BSSrcrep::lsrev($nrev));
updatelinkinfodb($projid, $packid, $rev, lsrev($nrev));
}
} elsif ($revfileto =~ /\.mrev$/) {
BSRevision::extract_old_meta($projid, $packid, $nrev);
Expand Down Expand Up @@ -504,6 +504,55 @@ sub lspackages_local {
return sort @packids;
}

#
# revision data access
#

sub revstat {
my ($rev, $filename, $md5) = @_;
return BSSrcrep::filestat($rev->{'project'}, $rev->{'package'}, $filename, $md5);
}

sub revopen {
my ($rev, $filename, $md5, $fd) = @_;
return BSSrcrep::fileopen($rev->{'project'}, $rev->{'package'}, $filename, $md5, $fd);
}

sub revreadstr {
my ($rev, $filename, $md5, $nonfatal) = @_;
return BSSrcrep::filereadstr($rev->{'project'}, $rev->{'package'}, $filename, $md5, $nonfatal);
}

sub revreadxml {
my ($rev, $filename, $md5, $dtd, $nonfatal) = @_;
return BSSrcrep::filereadxml($rev->{'project'}, $rev->{'package'}, $filename, $md5, $dtd, $nonfatal);
}

sub revfilename {
my ($rev, $filename, $md5) = @_;
return BSSrcrep::filepath($rev->{'project'}, $rev->{'package'}, $filename, $md5);
}

sub revcpiofile {
my ($rev, $filename, $md5, $forcehandle) = @_;
return BSSrcrep::cpiofile($rev->{'project'}, $rev->{'package'}, $filename, $md5, $forcehandle);
}

sub lsrev {
my ($rev, $linkinfo) = @_;
die("nothing known\n") unless $rev;
my $projid = $rev->{'project'};
my $packid = $rev->{'package'};
my $srcmd5 = $rev->{'srcmd5'};
die("revision project missing\n") unless defined $projid;
die("revision package missing\n") unless defined $packid;
die("no such revision\n") unless defined $srcmd5;
my $files = BSSrcrep::lsfiles($projid, $packid, $srcmd5, $linkinfo);
# hack: do not list _signkey in project meta
delete $files->{'_signkey'} if $packid eq '_project' && !$rev->{'keepsignkey'};
return $files;
}

#
# small helpers
#
Expand All @@ -512,8 +561,8 @@ sub readproj_local {
my $proj;
if ($revid) {
my $rev = getrev_meta($projid, undef, $revid);
my $files = $rev ? BSSrcrep::lsrev($rev) : {};
$proj = BSSrcrep::repreadxml($rev, '_meta', $files->{'_meta'}, $BSXML::proj, 1) if $files->{'_meta'};
my $files = $rev ? lsrev($rev) : {};
$proj = revreadxml($rev, '_meta', $files->{'_meta'}, $BSXML::proj, 1) if $files->{'_meta'};
} else {
$proj = readxml("$projectsdir/$projid.xml", $BSXML::proj, 1);
}
Expand All @@ -525,9 +574,9 @@ sub readpack_local {
my ($projid, $packid, $nonfatal, $revid) = @_;
my $pack;
if ($revid) {
my $rev = BSRevision::getrev_meta($projid, $packid, $revid);
my $files = $rev ? BSSrcrep::lsrev($rev) : {};
$pack = BSSrcrep::repreadxml($rev, '_meta', $files->{'_meta'}, $BSXML::pack, 1) if $files->{'_meta'};
my $rev = getrev_meta($projid, $packid, $revid);
my $files = $rev ? lsrev($rev) : {};
$pack = revreadxml($rev, '_meta', $files->{'_meta'}, $BSXML::pack, 1) if $files->{'_meta'};
} else {
$pack = readxml("$projectsdir/$projid.pkg/$packid.xml", $BSXML::pack, 1);
}
Expand Down
54 changes: 27 additions & 27 deletions src/backend/BSSrcServer/Link.pm
Expand Up @@ -38,7 +38,7 @@ my $uploaddir = "$srcrep/:upload";
our $getrev = \&BSSrcServer::Local::getrev;

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


Expand Down Expand Up @@ -213,8 +213,8 @@ sub applylink {
my $lerror = BSSrcrep::getlinkerror($llnk->{'project'}, $llnk->{'package'}, $md5);
return $lerror if $lerror;
}
my $flnk = BSSrcrep::lsrev($llnk);
my $fsrc = BSSrcrep::lsrev($lsrc);
my $flnk = BSRevision::lsrev($llnk);
my $fsrc = BSRevision::lsrev($lsrc);
my $l = $llnk->{'link'};
my $patches = $l->{'patches'} || {};
my @patches = ();
Expand Down Expand Up @@ -281,12 +281,12 @@ sub applylink {
for my $f (sort keys %$fsrc) {
next if $flnk->{$f} && !$apply{$f};
BSSrcrep::copyonefile_tmp($lsrc->{'project'}, $lsrc->{'package'}, $f, $fsrc->{$f}, "$tmpdir/$f");
$fl{$f} = BSSrcrep::repfilename($lsrc, $f, $fsrc->{$f});
$fl{$f} = BSRevision::revfilename($lsrc, $f, $fsrc->{$f});
}
for my $f (sort keys %$flnk) {
next if $apply{$f} || $f eq '_link';
BSSrcrep::copyonefile_tmp($llnk->{'project'}, $llnk->{'package'}, $f, $flnk->{$f}, "$tmpdir/$f");
$fl{$f} = BSSrcrep::repfilename($llnk, $f, $flnk->{$f});
$fl{$f} = BSRevision::revfilename($llnk, $f, $flnk->{$f});
}
}
my $failed;
Expand All @@ -306,7 +306,7 @@ sub applylink {
my %brev = (%$lsrc, 'srcmd5' => $baserev);
my $fbas;
eval {
$fbas = BSSrcrep::lsrev(\%brev);
$fbas = BSRevision::lsrev(\%brev);
};
return "baserev $baserev does not exist" unless $fbas;
return "baserev is link" if $fbas->{'_link'};
Expand All @@ -326,13 +326,13 @@ sub applylink {
if ($mbas eq $mlnk) {
next if $msrc eq '';
BSSrcrep::copyonefile_tmp($lsrc->{'project'}, $lsrc->{'package'}, $f, $fsrc->{$f}, "$tmpdir/$f");
$fl{$f} = BSSrcrep::repfilename($lsrc, $f, $fsrc->{$f});
$fl{$f} = BSRevision::revfilename($lsrc, $f, $fsrc->{$f});
next;
}
if ($mbas eq $msrc || $mlnk eq $msrc) {
next if $mlnk eq '';
BSSrcrep::copyonefile_tmp($llnk->{'project'}, $llnk->{'package'}, $f, $flnk->{$f}, "$tmpdir/$f");
$fl{$f} = BSSrcrep::repfilename($llnk, $f, $flnk->{$f});
$fl{$f} = BSRevision::revfilename($llnk, $f, $flnk->{$f});
next;
}
if ($mbas eq '' || $msrc eq '' || $mlnk eq '') {
Expand Down Expand Up @@ -427,7 +427,7 @@ sub applylink {
if (!($pid = xfork())) {
delete $SIG{'__DIE__'};
chdir($tmpdir) || die("$tmpdir: $!\n");
my $pnfile = BSSrcrep::repfilename($llnk, $pn, $flnk->{$pn});
my $pnfile = BSRevision::revfilename($llnk, $pn, $flnk->{$pn});
open(STDIN, '<', $pnfile) || die("$pnfile: $!\n");
open(STDOUT, '>>', ".log") || die(".log: $!\n");
open(STDERR, '>&STDOUT');
Expand Down Expand Up @@ -542,7 +542,7 @@ sub handlelinks {
my $vrevdone;
my $lrev = $rev;
while ($files->{'_link'}) {
my $l = BSSrcrep::repreadxml($lrev, '_link', $files->{'_link'}, $BSXML::link, 1);
my $l = BSRevision::revreadxml($lrev, '_link', $files->{'_link'}, $BSXML::link, 1);
return '_link is bad' unless $l;
my $cicount = $l->{'cicount'} || 'add';
eval {
Expand Down Expand Up @@ -637,7 +637,7 @@ sub handlelinks {
$oldl = $l;
}
$rev->{'srcmd5'} = $md5;
return BSSrcrep::lsrev($rev, $li);
return BSRevision::lsrev($rev, $li);
}

sub rundiff {
Expand Down Expand Up @@ -682,9 +682,9 @@ sub keeplink {
return $files if !defined($files) || !%$files;
return $files if $files->{'_link'};
$orev ||= $getrev->($projid, $packid, 'latest');
my $ofilesl = BSSrcrep::lsrev($orev);
my $ofilesl = BSRevision::lsrev($orev);
return $files unless $ofilesl && $ofilesl->{'_link'};
my $l = BSSrcrep::repreadxml($orev, '_link', $ofilesl->{'_link'}, $BSXML::link);
my $l = BSRevision::revreadxml($orev, '_link', $ofilesl->{'_link'}, $BSXML::link);
my $changedlink = 0;
my %lignore;
my $isbranch;
Expand Down Expand Up @@ -736,7 +736,7 @@ sub keeplink {
$ofiles = handlelinks(\%olrev, $ofilesl, \%li);
die("bad link: $ofiles\n") unless ref $ofiles;
$ltgtsrcmd5 = $li{'srcmd5'};
$ofilesfn{$_} = BSSrcrep::repfilename(\%olrev, $_, $ofiles->{$_}) for keys %$ofiles;
$ofilesfn{$_} = BSRevision::revfilename(\%olrev, $_, $ofiles->{$_}) for keys %$ofiles;
}

# get link target file list
Expand All @@ -746,7 +746,7 @@ sub keeplink {
my $ltgtfiles;
if ($ltgtsrcmd5) {
$ltgtrev = {'project' => $ltgtprojid, 'package' => $ltgtpackid, 'srcmd5' => $ltgtsrcmd5};
$ltgtfiles = BSSrcrep::lsrev($ltgtrev);
$ltgtfiles = BSRevision::lsrev($ltgtrev);
} else {
$ltgtrev = $getrev->($ltgtprojid, $ltgtpackid, $linkrev || $l->{'rev'});
$ltgtfiles = lsrev_expanded($ltgtrev);
Expand Down Expand Up @@ -788,7 +788,7 @@ sub keeplink {
if ($cgi->{'convertbranchtopatch'}) {
$ofilesl = {};
$ofiles = $ltgtfiles;
$ofilesfn{$_} = BSSrcrep::repfilename($ltgtrev, $_, $ofiles->{$_}) for keys %$ofiles;
$ofilesfn{$_} = BSRevision::revfilename($ltgtrev, $_, $ofiles->{$_}) for keys %$ofiles;
} elsif ($repair || $changedlink) {
# apply changed link
my $frominfo = {'project' => $ltgtprojid, 'package' => $ltgtpackid, 'srcmd5' => $ltgtsrcmd5};
Expand Down Expand Up @@ -831,12 +831,12 @@ sub keeplink {
if ($ofiles->{$file} eq $files->{$file}) {
next;
}
if (!isascii(BSSrcrep::repfilename($orev, $file, $files->{$file})) || !isascii($ofilesfn{$file})) {
if (!isascii(BSRevision::revfilename($orev, $file, $files->{$file})) || !isascii($ofilesfn{$file})) {
$nfiles->{$file} = $files->{$file};
next;
}
} else {
if (!isascii(BSSrcrep::repfilename($orev, $file, $files->{$file}))) {
if (!isascii(BSRevision::revfilename($orev, $file, $files->{$file}))) {
$nfiles->{$file} = $files->{$file};
next;
}
Expand All @@ -853,7 +853,7 @@ sub keeplink {
}
# both are ascii, create diff
mkdir_p($uploaddir);
if (!rundiff($ofiles->{$file} ? $ofilesfn{$file} : '/dev/null', BSSrcrep::repfilename($orev, $file, $files->{$file}), $file, "$uploaddir/$$")) {
if (!rundiff($ofiles->{$file} ? $ofilesfn{$file} : '/dev/null', BSRevision::revfilename($orev, $file, $files->{$file}), $file, "$uploaddir/$$")) {
$nfiles->{$file} = $files->{$file};
}
}
Expand Down Expand Up @@ -897,7 +897,7 @@ sub integratelink {
my ($files, $projid, $packid, $rev, $ofiles, $oprojid, $opackid, $l, $orev) = @_;

# append patches from link l to link nl
my $nl = BSSrcrep::repreadxml($rev, '_link', $files->{'_link'}, $BSXML::link);
my $nl = BSRevision::revreadxml($rev, '_link', $files->{'_link'}, $BSXML::link);

# FIXME: remove hunks from patches that deal with replaced/deleted files
my $nlchanged;
Expand Down Expand Up @@ -945,7 +945,7 @@ sub integratelink {
# and integrate
delete $ofiles->{'_link'};
$ofiles = keeplink({'convertbranchtopatch' => 1, 'linkrev' => 'base'}, $oprojid, $opackid, $ofiles, $orev);
$l = BSSrcrep::repreadxml($orev, '_link', $ofiles->{'_link'}, $BSXML::link);
$l = BSRevision::revreadxml($orev, '_link', $ofiles->{'_link'}, $BSXML::link);
}

if (!$nlisbranch && $l->{'patches'}) {
Expand Down Expand Up @@ -995,9 +995,9 @@ sub linkinfo_addtarget {
my ($rev, $linkinfo) = @_;
my %lrev = %$rev;
$lrev{'srcmd5'} = $linkinfo->{'lsrcmd5'} if $linkinfo->{'lsrcmd5'};
my $files = BSSrcrep::lsrev(\%lrev);
my $files = BSRevision::lsrev(\%lrev);
die("linkinfo_addtarget: not a link?\n") unless $files->{'_link'};
my $l = BSSrcrep::repreadxml(\%lrev, '_link', $files->{'_link'}, $BSXML::link, 1);
my $l = BSRevision::revreadxml(\%lrev, '_link', $files->{'_link'}, $BSXML::link, 1);
if ($l) {
$linkinfo->{'project'} = defined($l->{'project'}) ? $l->{'project'} : $lrev{'project'};
$linkinfo->{'package'} = defined($l->{'package'}) ? $l->{'package'} : $lrev{'package'};
Expand All @@ -1017,7 +1017,7 @@ sub findlastworkinglink {
for my $cand (@cand) {
my $candrev = {'project' => $projid, 'package' => $packid, 'srcmd5' => $cand};
my %li;
my $files = BSSrcrep::lsrev($candrev, \%li);
my $files = BSRevision::lsrev($candrev, \%li);
next unless $li{'lsrcmd5'} && $li{'lsrcmd5'} eq $rev->{'srcmd5'};
$cand{$cand} = $li{'srcmd5'};
}
Expand All @@ -1027,9 +1027,9 @@ sub findlastworkinglink {

while (1) {
my $lrev = {'project' => $projid, 'package' => $packid, 'srcmd5' => $rev->{'srcmd5'}};
my $lfiles = BSSrcrep::lsrev($lrev);
my $lfiles = BSRevision::lsrev($lrev);
return undef unless $lfiles;
my $l = BSSrcrep::repreadxml($lrev, '_link', $lfiles->{'_link'}, $BSXML::link, 1);
my $l = BSRevision::revreadxml($lrev, '_link', $lfiles->{'_link'}, $BSXML::link, 1);
return undef unless $l;
$projid = $l->{'project'} if exists $l->{'project'};
$packid = $l->{'package'} if exists $l->{'package'};
Expand All @@ -1038,7 +1038,7 @@ sub findlastworkinglink {
next unless $cand{$cand};
my %li;
my $candrev = {'project' => $projid, 'package' => $packid, 'srcmd5' => $cand{$cand}};
BSSrcrep::lsrev($candrev, \%li);
BSRevision::lsrev($candrev, \%li);
$candrev->{'srcmd5'} = $li{'lsrcmd5'} if $li{'lsrcmd5'};
$candrev = BSRevision::findlastrev($candrev);
next unless $candrev;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/BSSrcServer/Projlink.pm
Expand Up @@ -40,10 +40,10 @@ sub get_frozenlinks {
my ($projid) = @_;
return $frozenlinks_cache->{$projid} if $frozenlinks_cache && exists $frozenlinks_cache->{$projid};
my $rev = BSRevision::getrev_meta($projid);
my $files = BSSrcrep::lsrev($rev);
my $files = BSRevision::lsrev($rev);
my $frozen;
if ($files->{'_frozenlinks'}) {
my $frozenx = BSSrcrep::repreadxml($rev, '_frozenlinks', $files->{'_frozenlinks'}, $BSXML::frozenlinks);
my $frozenx = BSRevision::revreadxml($rev, '_frozenlinks', $files->{'_frozenlinks'}, $BSXML::frozenlinks);
$frozen = {};
for my $fp (@{$frozenx->{'frozenlink'} || []}) {
my $n = defined($fp->{'project'}) ? $fp->{'project'} : '/all';
Expand Down

0 comments on commit 0f9603c

Please sign in to comment.