| Index: tools/telemetry/telemetry/util/cloud_storage.py
|
| diff --git a/tools/telemetry/telemetry/util/cloud_storage.py b/tools/telemetry/telemetry/util/cloud_storage.py
|
| index ed97ccbb4837bcbab573b4fab844fc0898e9c1f1..1e9fc4f9831455c249b8a9b3588d5a632b71843d 100644
|
| --- a/tools/telemetry/telemetry/util/cloud_storage.py
|
| +++ b/tools/telemetry/telemetry/util/cloud_storage.py
|
| @@ -15,6 +15,7 @@ import sys
|
| import tarfile
|
| import urllib2
|
|
|
| +from telemetry import decorators
|
| from telemetry.core import util
|
| from telemetry.util import path
|
|
|
| @@ -220,10 +221,8 @@ def Insert(bucket, remote_path, local_path, publicly_readable=False):
|
|
|
|
|
| def GetIfChanged(file_path, bucket):
|
| - """Gets the file at file_path if it has a hash file that doesn't match.
|
| -
|
| - If the file is not in Cloud Storage, log a warning instead of raising an
|
| - exception. We assume that the user just hasn't uploaded the file yet.
|
| + """Gets the file at file_path if it has a hash file that doesn't match or
|
| + if there is no local copy of file_path, but there is a hash file for it.
|
|
|
| Returns:
|
| True if the binary was changed.
|
| @@ -244,6 +243,25 @@ def GetIfChanged(file_path, bucket):
|
| Get(bucket, expected_hash, file_path)
|
| return True
|
|
|
| +# TODO(aiolos): remove @decorators.Cache for http://crbug.com/459787
|
| +@decorators.Cache
|
| +def GetFilesInDirectoryIfChanged(directory, bucket):
|
| + """ Scan the directory for .sha1 files, and download them from the given
|
| + bucket in cloud storage if the local and remote hash don't match or
|
| + there is no local copy.
|
| + """
|
| + if not os.path.isdir(directory):
|
| + raise ValueError('Must provide a valid directory.')
|
| + # Don't allow the root directory to be a serving_dir.
|
| + if directory == os.path.abspath(os.sep):
|
| + raise ValueError('Trying to serve root directory from HTTP server.')
|
| + for dirpath, _, filenames in os.walk(directory):
|
| + for filename in filenames:
|
| + path_name, extension = os.path.splitext(
|
| + os.path.join(dirpath, filename))
|
| + if extension != '.sha1':
|
| + continue
|
| + GetIfChanged(path_name, bucket)
|
|
|
| def CalculateHash(file_path):
|
| """Calculates and returns the hash of the file at file_path."""
|
|
|