Skip to content

Commit

Permalink
[backend] encode directories as dirs in cpio archives
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe authored and adrianschroeter committed Feb 19, 2013
1 parent 2b701fa commit aa83c85
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 64 deletions.
33 changes: 12 additions & 21 deletions src/backend/BSHTTP.pm
Expand Up @@ -196,7 +196,6 @@ 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 All @@ -220,7 +219,7 @@ sub cpio_receiver {
my $sizepad = $size;
$sizepad += 4 - ($size % 4) if $size % 4;
last if !$size && $name eq 'TRAILER!!!';
if ($param->{'acceptsubdirs'}) {
if ($param->{'acceptsubdirs'} || $param->{'createsubdirs'}) {
die("cpio filename is illegal: $name\n") if "/$name/" =~ /\/\.{0,2}\//s;
} else {
die("cpio filename contains a '/': $name\n") if $name =~ /\//s;
Expand Down Expand Up @@ -255,26 +254,18 @@ sub cpio_receiver {
my $ctx;
$ctx = Digest::MD5->new if $withmd5;
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'};
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 = $_;
if (($mode & 0xf000) == 0x4000 && $param->{'createsubdirs'}) {
die("directory has non-zero size\n") if $sizepad;
if (! -d $filename) {
unlink($filename) unless $param->{'no_unlink'};
mkdir($filename) || die("mkdir $filename: $!\n");
}
$filename = "$dn$subdir$f";
} else {
die("can only unpack plain files from cpio archive, file $name, mode was $mode\n") unless ($mode & 0xf000) == 0x8000;
unlink($filename) unless $param->{'no_unlink'};
open(F, '>', $filename) || die("$filename: $!\n");
}
open(F, '>', "$filename") || die("$filename: $!\n");
} else {
$ent->{'data'} = '';
}
Expand All @@ -291,11 +282,11 @@ sub cpio_receiver {
}
$ctx->add($size >= 0 ? $data : substr($data, 0, $m)) if $ctx;
}
if (defined($dn)) {
if (defined($dn) && ($mode & 0xf000) != 0x4000) {
close(F) || die("close: $!\n");
utime($mtime, $mtime, "$dn/$name");
}
$ent->{'md5'} = $ctx->hexdigest if $ctx;
$ent->{'md5'} = $ctx->hexdigest if $ctx && ($mode & 0xf000) != 0x4000;
$param->{'cpiopostfile'}->($param, $ent) if $param->{'cpiopostfile'};
}
return \@res;
Expand Down
25 changes: 7 additions & 18 deletions src/backend/bs_dispatch
Expand Up @@ -96,31 +96,20 @@ sub getcodemd5 {
my %new;
my $doclean;
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);
push @files, map {"Build/$_"} grep {!/^\./} ls("$dir/Build");
push @files, map {"emulator/$_"} grep {!/^\./} ls("$dir/emulator");
$cache ||= {};
for my $file (@files) {
my $f;
if ($bfiles{$file}) {
$f = "Build/$file";
} elsif ($efiles{$file}) {
$f = "emulator/$file";
} else {
$f = "$file";
}
next unless -f "$dir/$f";
for my $file (sort @files) {
next unless -f "$dir/$file";
my @s = stat _;
my $id = "$s[9]/$s[7]/$s[1]";
$new{$id} = 1;
if ($cache->{$id}) {
$md5 .= "$cache->{$id} $f\n";
$md5 .= "$cache->{$id} $file\n";
next;
}
$cache->{$id} = Digest::MD5::md5_hex(readstr("$dir/$f"));
$md5 .= "$cache->{$id} $f\n";
$cache->{$id} = Digest::MD5::md5_hex(readstr("$dir/$file"));
$md5 .= "$cache->{$id} $file\n";
$doclean = 1;
}
if ($doclean) {
Expand Down
12 changes: 4 additions & 8 deletions src/backend/bs_repserver
Expand Up @@ -2911,14 +2911,10 @@ sub getcode {
my @send;
push @send, getqemuinterpreters() if $dir eq 'build';
for my $file (grep {!/^\./} ls($dir)) {
if ($file eq 'Build' && -d "$dir/$file") {
for my $file2 (grep {!/^\./} ls("$dir/Build")) {
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"};
if (($file eq 'Build' || $file eq 'emulator') && -d "$dir/$file") {
push @send, {'name' => $file, 'mode' => 0x41ed, 'data' => ''};
for my $file2 (grep {!/^\./} ls("$dir/$file")) {
push @send, {'name' => "$file/$file2", 'filename' => "$dir/$file/$file2"};
}
}
next unless -f "$dir/$file";
Expand Down
24 changes: 7 additions & 17 deletions src/backend/bs_worker
Expand Up @@ -670,23 +670,13 @@ sub send_state {
sub codemd5 {
my ($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;
my @bfiles = map {"Build/$_"} grep {!/^\./} ls("$dir/Build");
my @efiles = map {"emulator/$_"} grep {!/^\./} ls("$dir/emulator");
@files = sort(@files, @bfiles, @efiles);
my $md5 = '';
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";
next if -l "$dir/$file" || -d _;
$md5 .= Digest::MD5::md5_hex(readstr("$dir/$file"))." $file\n";
}
$md5 = Digest::MD5::md5_hex($md5);
return $md5;
Expand Down Expand Up @@ -721,7 +711,7 @@ sub getcode {
'directory' => $ndir,
'timeout' => $gettimeout,
'withmd5' => 1,
'createdirectories' => 1,
'createsubdirs' => 1,
'receiver' => \&BSHTTP::cpio_receiver,
});
die("getcode error\n") unless $res;
Expand All @@ -734,7 +724,7 @@ sub getcode {
} elsif ($dir eq 'build') {
symlink('.', "$ndir/Date") || die("symlink: $!\n");
symlink('.', "$ndir/Time") || die("symlink: $!\n");
# we just change everyfile to be on the safe side
# we just change every file to be on the safe side
chmod(0755, "$ndir/$_->{'name'}") for @$res;
}

Expand All @@ -749,7 +739,7 @@ sub getcode {
}
my $md5 = '';
for my $file (sort {$a->{'name'} cmp $b->{'name'}} @$res) {
$md5 .= "$file->{'md5'} $file->{'name'}\n";
$md5 .= "$file->{'md5'} $file->{'name'}\n" if $file->{'md5'};
}
$md5 = Digest::MD5::md5_hex($md5);
return $md5;
Expand Down

0 comments on commit aa83c85

Please sign in to comment.