| 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 posixpath | 5 import posixpath |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 from file_system import FileSystem, StatInfo, FileNotFoundError | 8 from file_system import FileSystem, StatInfo, FileNotFoundError |
| 9 from future import Future | 9 from future import Future |
| 10 from path_util import IsDirectory, ToDirectory | 10 from path_util import IsDirectory, ToDirectory |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return dir_stat | 53 return dir_stat |
| 54 # Was a file stat. Extract that file. | 54 # Was a file stat. Extract that file. |
| 55 file_version = dir_stat.child_versions.get(file_path) | 55 file_version = dir_stat.child_versions.get(file_path) |
| 56 if file_version is None: | 56 if file_version is None: |
| 57 raise FileNotFoundError('No stat found for %s in %s (found %s)' % | 57 raise FileNotFoundError('No stat found for %s in %s (found %s)' % |
| 58 (path, dir_path, dir_stat.child_versions)) | 58 (path, dir_path, dir_stat.child_versions)) |
| 59 return StatInfo(file_version) | 59 return StatInfo(file_version) |
| 60 | 60 |
| 61 dir_stat = self._stat_object_store.Get(dir_path).Get() | 61 dir_stat = self._stat_object_store.Get(dir_path).Get() |
| 62 if dir_stat is not None: | 62 if dir_stat is not None: |
| 63 return Future(value=make_stat_info(dir_stat)) | 63 return Future(callback=lambda: make_stat_info(dir_stat)) |
| 64 | 64 |
| 65 def next(dir_stat): | 65 def next(dir_stat): |
| 66 assert dir_stat is not None # should have raised a FileNotFoundError | 66 assert dir_stat is not None # should have raised a FileNotFoundError |
| 67 # We only ever need to cache the dir stat. | 67 # We only ever need to cache the dir stat. |
| 68 self._stat_object_store.Set(dir_path, dir_stat) | 68 self._stat_object_store.Set(dir_path, dir_stat) |
| 69 return make_stat_info(dir_stat) | 69 return make_stat_info(dir_stat) |
| 70 return self._MemoizedStatAsyncFromFileSystem(dir_path).Then(next) | 70 return self._MemoizedStatAsyncFromFileSystem(dir_path).Then(next) |
| 71 | 71 |
| 72 @memoize | 72 @memoize |
| 73 def _MemoizedStatAsyncFromFileSystem(self, dir_path): | 73 def _MemoizedStatAsyncFromFileSystem(self, dir_path): |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return new_results | 125 return new_results |
| 126 # Read in the values that were uncached or old. | 126 # Read in the values that were uncached or old. |
| 127 return self._file_system.Read(set(paths) - set(fresh_data.iterkeys()), | 127 return self._file_system.Read(set(paths) - set(fresh_data.iterkeys()), |
| 128 skip_not_found=skip_not_found).Then(next) | 128 skip_not_found=skip_not_found).Then(next) |
| 129 | 129 |
| 130 def GetIdentity(self): | 130 def GetIdentity(self): |
| 131 return self._file_system.GetIdentity() | 131 return self._file_system.GetIdentity() |
| 132 | 132 |
| 133 def __repr__(self): | 133 def __repr__(self): |
| 134 return '%s of <%s>' % (type(self).__name__, repr(self._file_system)) | 134 return '%s of <%s>' % (type(self).__name__, repr(self._file_system)) |
| OLD | NEW |