| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 errno | |
| 6 import logging | 5 import logging |
| 7 import os | 6 import os |
| 8 import stat | 7 import stat |
| 9 | 8 |
| 10 from catapult_base import cloud_storage | 9 from catapult_base import cloud_storage |
| 11 | 10 |
| 12 from catapult_base.dependency_manager import exceptions | 11 from catapult_base.dependency_manager import exceptions |
| 13 | 12 |
| 14 class CloudStorageInfo(object): | 13 class CloudStorageInfo(object): |
| 15 def __init__(self, cs_bucket, cs_hash, download_path, cs_remote_path, | 14 def __init__(self, cs_bucket, cs_hash, download_path, cs_remote_path, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 needed file. | 56 needed file. |
| 58 CloudStorageError: If another error occured while downloading the remote | 57 CloudStorageError: If another error occured while downloading the remote |
| 59 path. | 58 path. |
| 60 FileNotFoundError: If the download was otherwise unsuccessful. | 59 FileNotFoundError: If the download was otherwise unsuccessful. |
| 61 """ | 60 """ |
| 62 if not self._has_minimum_data: | 61 if not self._has_minimum_data: |
| 63 return None | 62 return None |
| 64 | 63 |
| 65 download_dir = os.path.dirname(self._download_path) | 64 download_dir = os.path.dirname(self._download_path) |
| 66 if not os.path.exists(download_dir): | 65 if not os.path.exists(download_dir): |
| 67 try: | 66 os.makedirs(download_dir) |
| 68 os.makedirs(download_dir) | |
| 69 except OSError as e: | |
| 70 # The logic above is racy, and os.makedirs will raise an OSError if | |
| 71 # the directory exists. | |
| 72 if e.errno != errno.EEXIST: | |
| 73 raise | |
| 74 | 67 |
| 75 dependency_path = self._download_path | 68 dependency_path = self._download_path |
| 76 cloud_storage.GetIfHashChanged( | 69 cloud_storage.GetIfHashChanged( |
| 77 self._cs_remote_path, self._download_path, self._cs_bucket, | 70 self._cs_remote_path, self._download_path, self._cs_bucket, |
| 78 self._cs_hash) | 71 self._cs_hash) |
| 79 if not os.path.exists(dependency_path): | 72 if not os.path.exists(dependency_path): |
| 80 raise exceptions.FileNotFoundError(dependency_path) | 73 raise exceptions.FileNotFoundError(dependency_path) |
| 81 | 74 |
| 82 logging.error('has archive_info %s', self._archive_info) | 75 logging.error('has archive_info %s', self._archive_info) |
| 83 if self.has_archive_info: | 76 if self.has_archive_info: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 100 @property | 93 @property |
| 101 def has_archive_info(self): | 94 def has_archive_info(self): |
| 102 return bool(self._archive_info) | 95 return bool(self._archive_info) |
| 103 | 96 |
| 104 def __repr__(self): | 97 def __repr__(self): |
| 105 return ( | 98 return ( |
| 106 'CloudStorageInfo(download_path=%s, cs_remote_path=%s, cs_bucket=%s, ' | 99 'CloudStorageInfo(download_path=%s, cs_remote_path=%s, cs_bucket=%s, ' |
| 107 'cs_hash=%s, version_in_cs=%s, archive_info=%s)' % ( | 100 'cs_hash=%s, version_in_cs=%s, archive_info=%s)' % ( |
| 108 self._download_path, self._cs_remote_path, self._cs_bucket, | 101 self._download_path, self._cs_remote_path, self._cs_bucket, |
| 109 self._cs_hash, self._version_in_cs, self._archive_info)) | 102 self._cs_hash, self._version_in_cs, self._archive_info)) |
| OLD | NEW |