| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import hashlib | 5 import hashlib |
| 6 import copy | 6 import copy |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 filename = os.path.join(self.archive_cache, filename) | 67 filename = os.path.join(self.archive_cache, filename) |
| 68 if not os.path.exists(filename): | 68 if not os.path.exists(filename): |
| 69 logging.info('File does not exist: %s.' % filename) | 69 logging.info('File does not exist: %s.' % filename) |
| 70 return False | 70 return False |
| 71 size = os.path.getsize(filename) | 71 size = os.path.getsize(filename) |
| 72 if size != archive.size: | 72 if size != archive.size: |
| 73 logging.info('File size does not match (%d vs %d): %s.' % (size, | 73 logging.info('File size does not match (%d vs %d): %s.' % (size, |
| 74 archive.size, filename)) | 74 archive.size, filename)) |
| 75 return False | 75 return False |
| 76 sha1_hash = hashlib.sha1() | 76 sha1_hash = hashlib.sha1() |
| 77 with open(filename) as f: | 77 with open(filename, 'rb') as f: |
| 78 sha1_hash.update(f.read()) | 78 sha1_hash.update(f.read()) |
| 79 if sha1_hash.hexdigest() != archive.GetChecksum(): | 79 if sha1_hash.hexdigest() != archive.GetChecksum(): |
| 80 logging.info('File hash does not match: %s.' % filename) | 80 logging.info('File hash does not match: %s.' % filename) |
| 81 return False | 81 return False |
| 82 return True | 82 return True |
| 83 | 83 |
| 84 def BytesUsedInCache(self): | 84 def BytesUsedInCache(self): |
| 85 """Determine number of bytes currently be in local archive cache.""" | 85 """Determine number of bytes currently be in local archive cache.""" |
| 86 total = 0 | 86 total = 0 |
| 87 for root, _, files in os.walk(self.archive_cache): | 87 for root, _, files in os.walk(self.archive_cache): |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return os.path.basename(path) | 380 return os.path.basename(path) |
| 381 | 381 |
| 382 | 382 |
| 383 def _ValidateArchive(archive, actual_sha1, actual_size): | 383 def _ValidateArchive(archive, actual_sha1, actual_size): |
| 384 if actual_size != archive.size: | 384 if actual_size != archive.size: |
| 385 raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( | 385 raise Error('Size mismatch on "%s". Expected %s but got %s bytes' % ( |
| 386 archive.url, archive.size, actual_size)) | 386 archive.url, archive.size, actual_size)) |
| 387 if actual_sha1 != archive.GetChecksum(): | 387 if actual_sha1 != archive.GetChecksum(): |
| 388 raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( | 388 raise Error('SHA1 checksum mismatch on "%s". Expected %s but got %s' % ( |
| 389 archive.url, archive.GetChecksum(), actual_sha1)) | 389 archive.url, archive.GetChecksum(), actual_sha1)) |
| OLD | NEW |