From c74960e87dda3b9056f494e5cf0ce0b1c4f92b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Fri, 15 Feb 2013 14:34:38 +0100 Subject: [PATCH] [backend] support download of build code with Build/ and emulator/ subdirectories --- src/backend/BSHTTP.pm | 20 +++++++++++++++++++- src/backend/bs_dispatch | 21 +++++++++++++++------ src/backend/bs_repserver | 9 ++++++++- src/backend/bs_worker | 33 ++++++++++++++++++++------------- 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/backend/BSHTTP.pm b/src/backend/BSHTTP.pm index 7c0c18289e6..59d4e70a063 100644 --- a/src/backend/BSHTTP.pm +++ b/src/backend/BSHTTP.pm @@ -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); @@ -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'} = ''; } diff --git a/src/backend/bs_dispatch b/src/backend/bs_dispatch index dff71eb2524..23d4a5ea761 100755 --- a/src/backend/bs_dispatch +++ b/src/backend/bs_dispatch @@ -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) { diff --git a/src/backend/bs_repserver b/src/backend/bs_repserver index 3e884d4aec5..8567af816ca 100755 --- a/src/backend/bs_repserver +++ b/src/backend/bs_repserver @@ -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 @@ -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"; diff --git a/src/backend/bs_worker b/src/backend/bs_worker index af006ed17c2..51293145dcc 100755 --- a/src/backend/bs_worker +++ b/src/backend/bs_worker @@ -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; @@ -699,14 +712,8 @@ 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({ @@ -714,6 +721,7 @@ sub getcode { 'directory' => $ndir, 'timeout' => $gettimeout, 'withmd5' => 1, + 'createdirectories' => 1, 'receiver' => \&BSHTTP::cpio_receiver, }); die("getcode error\n") unless $res; @@ -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