OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Reads a manifest, creates a tree of hardlinks and runs the test. | 6 """Reads a manifest, creates a tree of hardlinks and runs the test. |
7 | 7 |
8 Keeps a local cache. | 8 Keeps a local cache. |
9 """ | 9 """ |
10 | 10 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 logging.warn('Unknown file %s from cache' % f) | 181 logging.warn('Unknown file %s from cache' % f) |
182 # Insert as the oldest file. It will be deleted eventually if not | 182 # Insert as the oldest file. It will be deleted eventually if not |
183 # accessed. | 183 # accessed. |
184 self.state.insert(0, f) | 184 self.state.insert(0, f) |
185 | 185 |
186 # Ensure enough free space. | 186 # Ensure enough free space. |
187 while ( | 187 while ( |
188 self.min_free_space and | 188 self.min_free_space and |
189 self.state and | 189 self.state and |
190 get_free_space(self.cache_dir) < self.min_free_space): | 190 get_free_space(self.cache_dir) < self.min_free_space): |
191 os.remove(self.path(self.state.pop(0))) | 191 try: |
| 192 os.remove(self.path(self.state.pop(0))) |
| 193 except OSError as e: |
| 194 logging.error('Error attempting to delete a file\n%s' % e) |
192 | 195 |
193 # Ensure maximum cache size. | 196 # Ensure maximum cache size. |
194 if self.max_cache_size and self.state: | 197 if self.max_cache_size and self.state: |
195 sizes = [os.stat(self.path(f)).st_size for f in self.state] | 198 sizes = [os.stat(self.path(f)).st_size for f in self.state] |
196 while sizes and sum(sizes) > self.max_cache_size: | 199 while sizes and sum(sizes) > self.max_cache_size: |
197 # Delete the oldest item. | 200 # Delete the oldest item. |
198 os.remove(self.path(self.state.pop(0))) | 201 try: |
| 202 os.remove(self.path(self.state.pop(0))) |
| 203 except OSError as e: |
| 204 logging.error('Error attempting to delete a file\n%s' % e) |
199 sizes.pop(0) | 205 sizes.pop(0) |
200 | 206 |
201 self.save() | 207 self.save() |
202 | 208 |
203 def retrieve(self, item): | 209 def retrieve(self, item): |
204 """Retrieves a file from the remote and add it to the cache.""" | 210 """Retrieves a file from the remote and add it to the cache.""" |
205 assert not '/' in item | 211 assert not '/' in item |
206 try: | 212 try: |
207 index = self.state.index(item) | 213 index = self.state.index(item) |
208 # Was already in cache. Update it's LRU value. | 214 # Was already in cache. Update it's LRU value. |
209 self.state.pop(index) | 215 self.state.pop(index) |
210 self.state.append(item) | 216 self.state.append(item) |
211 return False | 217 return False |
212 except ValueError: | 218 except ValueError: |
213 out = self.path(item) | 219 out = self.path(item) |
214 download_or_copy(os.path.join(self.remote, item), out) | 220 download_or_copy(os.path.join(self.remote, item), out) |
215 self.state.append(item) | 221 if os.path.exists(out): |
| 222 self.state.append(item) |
| 223 else: |
| 224 logging.error('File, %s, not placed in cache' % item) |
216 return True | 225 return True |
217 finally: | 226 finally: |
218 self.save() | 227 self.save() |
219 | 228 |
220 def path(self, item): | 229 def path(self, item): |
221 """Returns the path to one item.""" | 230 """Returns the path to one item.""" |
222 return os.path.join(self.cache_dir, item) | 231 return os.path.join(self.cache_dir, item) |
223 | 232 |
224 def save(self): | 233 def save(self): |
225 """Saves the LRU ordering.""" | 234 """Saves the LRU ordering.""" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 parser.error('Unsupported args %s' % ' '.join(args)) | 315 parser.error('Unsupported args %s' % ' '.join(args)) |
307 | 316 |
308 manifest = json.load(open_remote(options.manifest)) | 317 manifest = json.load(open_remote(options.manifest)) |
309 return run_tha_test( | 318 return run_tha_test( |
310 manifest, os.path.abspath(options.cache), options.remote, | 319 manifest, os.path.abspath(options.cache), options.remote, |
311 options.max_cache_size, options.min_free_space) | 320 options.max_cache_size, options.min_free_space) |
312 | 321 |
313 | 322 |
314 if __name__ == '__main__': | 323 if __name__ == '__main__': |
315 sys.exit(main()) | 324 sys.exit(main()) |
OLD | NEW |