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