Bug 354166: Cache HashFile() calls. r=cf

This commit is contained in:
preed%mozilla.com 2007-08-09 22:10:53 +00:00
Родитель c61c6c0455
Коммит 3ca5a17d7e
2 изменённых файлов: 45 добавлений и 9 удалений

Просмотреть файл

@ -49,7 +49,7 @@ use English;
use File::Spec::Functions;
use MozBuild::Util qw(RunShellCommand MkdirWithPath);
use MozBuild::Util qw(RunShellCommand MkdirWithPath HashFile);
require Exporter;
@ -60,6 +60,7 @@ require Exporter;
EnsureDeliverablesDir
SubstitutePath
GetSnippetDirFromChannel
CachedHashFile
);
use strict;
@ -73,7 +74,8 @@ use vars qw($MAR_BIN $MBSDIFF_BIN $MAKE_BIN
$TMPDIR_PREFIX
%BOUNCER_PLATFORMS %AUS2_PLATFORMS
$DEFAULT_PARTIAL_MAR_OUTPUT_FILE
$DEFAULT_SNIPPET_BASE_DIR $DEFAULT_SNIPPET_TEST_DIR);
$DEFAULT_SNIPPET_BASE_DIR $DEFAULT_SNIPPET_TEST_DIR
$SNIPPET_CHECKSUM_HASH_CACHE);
$MAR_BIN = 'dist/host/bin/mar';
$MBSDIFF_BIN = 'dist/host/bin/mbsdiff';
@ -100,6 +102,36 @@ $DEFAULT_PARTIAL_MAR_OUTPUT_FILE = 'partial.mar';
$DEFAULT_SNIPPET_BASE_DIR = 'aus2';
$DEFAULT_SNIPPET_TEST_DIR = $DEFAULT_SNIPPET_BASE_DIR . '.test';
##
## Global, used by CachedHashFile()
##
$SNIPPET_CHECKSUM_HASH_CACHE = {};
sub CachedHashFile {
my %args = @_;
if (! exists($args{'file'}) || !exists($args{'type'})) {
die("ASSERT: CachedHashFile: null file and/or type");
}
# Let HashFile do all the heavy error checking lifting...
my $file = $args{'file'};
my $checksumType = $args{'type'};
if (! exists($SNIPPET_CHECKSUM_HASH_CACHE->{$file})) {
$SNIPPET_CHECKSUM_HASH_CACHE->{$file} = {};
}
if (! exists($SNIPPET_CHECKSUM_HASH_CACHE->{$file}->{$checksumType})) {
$SNIPPET_CHECKSUM_HASH_CACHE->{$file}->{$checksumType} =
HashFile(file => $file, type => $checksumType);
}
return $SNIPPET_CHECKSUM_HASH_CACHE->{$file}->{$checksumType};
}
sub EnsureDeliverablesDir
{
my %args = @_;

Просмотреть файл

@ -58,9 +58,10 @@ use MozAUSLib qw(CreatePartialMarFile
GetAUS2PlatformStrings
EnsureDeliverablesDir
ValidateToolsDirectory SubstitutePath
GetSnippetDirFromChannel);
GetSnippetDirFromChannel
CachedHashFile);
use MozBuild::Util qw(MkdirWithPath RunShellCommand DownloadFile HashFile);
use MozBuild::Util qw(MkdirWithPath RunShellCommand DownloadFile);
$Data::Dumper::Indent = 1;
@ -723,7 +724,8 @@ sub CreateCompletePatchinfo {
my $hash_type = $DEFAULT_HASH_TYPE;
$complete_patch->{'hash_type'} = $hash_type;
$complete_patch->{'hash_value'} = HashFile(file => $to_path,
$complete_patch->{'hash_value'} = CachedHashFile(
file => $to_path,
type => $hash_type);
$complete_patch->{'hash_value'} =~ s/^(\S+)\s+.*$/$1/g;
@ -978,8 +980,9 @@ sub CreatePastReleasePatchinfo {
my $hash_type = $DEFAULT_HASH_TYPE;
$completePatch->{'hash_type'} = $hash_type;
$completePatch->{'hash_value'} = HashFile(file => $to_path,
type => $hash_type);
$completePatch->{'hash_value'} = CachedHashFile(
file => $to_path,
type => $hash_type);
$completePatch->{'build_id'} = $patchLocaleNode->{'build_id'};
$completePatch->{'appv'} = $snippetToAppVersion;
$completePatch->{'extv'} = $patchLocaleNode->{'extv'};
@ -1116,7 +1119,7 @@ sub CreatePartialPatchinfo {
version => $to->{'appv'},
locale => $l );
my $partialPatchHash = HashFile(file => $partial_pathname,
my $partialPatchHash = CachedHashFile(file => $partial_pathname,
type => $DEFAULT_HASH_TYPE);
my $partialPatchSize = (stat($partial_pathname))[$ST_SIZE];
@ -1132,7 +1135,8 @@ sub CreatePartialPatchinfo {
version => $to->{'appv'},
locale => $l );
my $completePatchHash = HashFile(file => $complete_pathname,
my $completePatchHash = CachedHashFile(
file => $complete_pathname,
type => $DEFAULT_HASH_TYPE);
my $completePatchSize = (stat($complete_pathname))[$ST_SIZE];