Skip to content

Commit

Permalink
[backend] support download of build code with Build/ and emulator/ su…
Browse files Browse the repository at this point in the history
…bdirectories
  • Loading branch information
adrianschroeter committed Feb 15, 2013
1 parent a1e42a8 commit c74960e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
20 changes: 19 additions & 1 deletion src/backend/BSHTTP.pm
Expand Up @@ -196,6 +196,7 @@ sub cpio_receiver {
my @res;
my $dn = $param->{'directory'};
my $withmd5 = $param->{'withmd5'};
my $createdirectories = $param->{'createdirectories'};
local *F;
while(1) {
my $cpiohead = read_data($hdr, 110, 1);
Expand Down Expand Up @@ -256,7 +257,24 @@ sub cpio_receiver {
if (defined($dn)) {
die("can only unpack plain files from cpio archive $name, mode was $mode\n") unless ($mode & 0xf000) == 0x8000;
unlink("$dn/$name") unless $param->{'no_unlink'};
open(F, '>', "$dn/$name") || die("$dn/$name: $!\n");
my $filename = "$dn/$name";
if (defined($createdirectories)) {
my @a = split(/::/, $name);
my $f;
my $dir;
my $subdir ="/";
for (@a) {
$dir = $f;
if ($dir) {
$subdir = "$subdir$dir";
mkdir("$dn$subdir");
$subdir = "$subdir/";
};
$f = $_;
}
$filename = "$dn$subdir$f";
}
open(F, '>', "$filename") || die("$filename: $!\n");
} else {
$ent->{'data'} = '';
}
Expand Down
21 changes: 15 additions & 6 deletions src/backend/bs_dispatch
Expand Up @@ -97,21 +97,30 @@ sub getcodemd5 {
my $doclean;
my @files = grep {!/^\./} ls($dir);
my @bfiles = grep {!/^\./} ls("$dir/Build");
my @efiles = grep {!/^\./} ls("$dir/emulator");
my %bfiles = map {$_ => 1} @bfiles;
@files = sort(@files, @bfiles);
my %efiles = map {$_ => 1} @efiles;
@files = sort(@files, @bfiles, @efiles);
$cache ||= {};
for my $file (@files) {
my $f = $bfiles{$file} ? "$dir/Build/$file" : "$dir/$file";
next unless -f $f;
my $f;
if ($bfiles{$file}) {
$f = "Build/$file";
} elsif ($efiles{$file}) {
$f = "emulator/$file";
} else {
$f = "$file";
}
next unless -f "$dir/$f";
my @s = stat _;
my $id = "$s[9]/$s[7]/$s[1]";
$new{$id} = 1;
if ($cache->{$id}) {
$md5 .= "$cache->{$id} $file\n";
$md5 .= "$cache->{$id} $f\n";
next;
}
$cache->{$id} = Digest::MD5::md5_hex(readstr($f));
$md5 .= "$cache->{$id} $file\n";
$cache->{$id} = Digest::MD5::md5_hex(readstr("$dir/$f"));
$md5 .= "$cache->{$id} $f\n";
$doclean = 1;
}
if ($doclean) {
Expand Down
9 changes: 8 additions & 1 deletion src/backend/bs_repserver
Expand Up @@ -2888,6 +2888,8 @@ sub abortbuild {
}

#
# OBSOLETE: qemu shall be installed into the target system
# FIXME3.0: remove this
# if there is a qemu dir in OBS backend install dir workers load qemu from OBS backend server
# this is similiar to the rest of build script code
# if that does also not exist, workers copy qemu from worker local installed qemu
Expand All @@ -2911,7 +2913,12 @@ sub getcode {
for my $file (grep {!/^\./} ls($dir)) {
if ($file eq 'Build' && -d "$dir/$file") {
for my $file2 (grep {!/^\./} ls("$dir/Build")) {
push @send, {'name' => "$file2", 'filename' => "$dir/Build/$file2"};
push @send, {'name' => "Build::$file2", 'filename' => "$dir/Build/$file2"};
}
}
if ($file eq 'emulator' && -d "$dir/$file") {
for my $file2 (grep {!/^\./} ls("$dir/emulator")) {
push @send, {'name' => "emulator::$file2", 'filename' => "$dir/emulator/$file2"};
}
}
next unless -f "$dir/$file";
Expand Down
33 changes: 20 additions & 13 deletions src/backend/bs_worker
Expand Up @@ -669,11 +669,24 @@ sub send_state {

sub codemd5 {
my ($dir) = @_;
my @files = ls($dir);
my @files = grep {!/^\./} ls($dir);
my @bfiles = grep {!/^\./} ls("$dir/Build");
my @efiles = grep {!/^\./} ls("$dir/emulator");
my %bfiles = map {$_ => 1} @bfiles;
my %efiles = map {$_ => 1} @efiles;
@files = sort(@files, @bfiles, @efiles);
my $md5 = '';
for my $file (sort @files) {
next if -l "$dir/$file" || -d "$dir/$file";
$md5 .= Digest::MD5::md5_hex(readstr("$dir/$file"))." $file\n";
for my $file (@files) {
my $f;
if ($bfiles{$file}) {
$f = "Build/$file";
} elsif ($efiles{$file}) {
$f = "emulator/$file";
} else {
$f = "$file";
}
next if -l "$dir/$f" || -d "$dir/$f";
$md5 .= Digest::MD5::md5_hex(readstr("$dir/$f"))." $f\n";
}
$md5 = Digest::MD5::md5_hex($md5);
return $md5;
Expand All @@ -699,21 +712,16 @@ sub getcode {
my $odir = "$dir.old";

# clean up stale runs
if (-e $ndir) {
unlink("$ndir/$_") for ls($ndir);
rmdir($ndir) || die("rmdir $ndir: $!\n");
}
if (-e $odir) {
unlink("$odir/$_") for ls($odir);
rmdir($odir) || die("rmdir $odir: $!\n");
}
rm_rf($ndir) if -e $ndir;
rm_rf($odir) if -e $odir;

mkdir($ndir) || die("mkdir $ndir: $!\n");
my $res = BSRPC::rpc({
'uri' => $uri,
'directory' => $ndir,
'timeout' => $gettimeout,
'withmd5' => 1,
'createdirectories' => 1,
'receiver' => \&BSHTTP::cpio_receiver,
});
die("getcode error\n") unless $res;
Expand All @@ -724,7 +732,6 @@ sub getcode {
chmod(0755, "$ndir/bs_worker");
die("bs_worker selftest failed\n") if system("cd $ndir && ./bs_worker --selftest");
} elsif ($dir eq 'build') {
symlink('.', "$ndir/Build") || die("symlink: $!\n");
symlink('.', "$ndir/Date") || die("symlink: $!\n");
symlink('.', "$ndir/Time") || die("symlink: $!\n");
# we just change everyfile to be on the safe side
Expand Down

0 comments on commit c74960e

Please sign in to comment.