| Index: chrome/common/extensions/docs/server2/caching_file_system.py
|
| diff --git a/chrome/common/extensions/docs/server2/caching_file_system.py b/chrome/common/extensions/docs/server2/caching_file_system.py
|
| index 59d8030c33af19dbdf04f0c092ad32d776009f3b..c0ff5d0b92d2256cf64464ed8b26f706837b1daa 100644
|
| --- a/chrome/common/extensions/docs/server2/caching_file_system.py
|
| +++ b/chrome/common/extensions/docs/server2/caching_file_system.py
|
| @@ -63,14 +63,12 @@ class CachingFileSystem(FileSystem):
|
| if dir_stat is not None:
|
| return Future(value=make_stat_info(dir_stat))
|
|
|
| - dir_stat_future = self._MemoizedStatAsyncFromFileSystem(dir_path)
|
| - def resolve():
|
| - dir_stat = dir_stat_future.Get()
|
| + def next(dir_stat):
|
| assert dir_stat is not None # should have raised a FileNotFoundError
|
| # We only ever need to cache the dir stat.
|
| self._stat_object_store.Set(dir_path, dir_stat)
|
| return make_stat_info(dir_stat)
|
| - return Future(callback=resolve)
|
| + return self._MemoizedStatAsyncFromFileSystem(dir_path).Then(next)
|
|
|
| @memoize
|
| def _MemoizedStatAsyncFromFileSystem(self, dir_path):
|
| @@ -93,18 +91,17 @@ class CachingFileSystem(FileSystem):
|
| # with a value.
|
| stat_futures = {}
|
|
|
| - def swallow_file_not_found_error(future):
|
| - def resolve():
|
| - try: return future.Get()
|
| - except FileNotFoundError: return Nnone
|
| - return Future(callback=resolve)
|
| + def handle(error):
|
| + if isinstance(error, FileNotFoundError):
|
| + return None
|
| + raise error
|
|
|
| for path in paths:
|
| stat_value = cached_stat_values.get(path)
|
| if stat_value is None:
|
| stat_future = self.StatAsync(path)
|
| if skip_not_found:
|
| - stat_future = swallow_file_not_found_error(stat_future)
|
| + stat_future = stat_future.Then(lambda x: x, handle)
|
| else:
|
| stat_future = Future(value=stat_value)
|
| stat_futures[path] = stat_future
|
| @@ -120,19 +117,16 @@ class CachingFileSystem(FileSystem):
|
| # Everything was cached and up-to-date.
|
| return Future(value=fresh_data)
|
|
|
| - # Read in the values that were uncached or old.
|
| - read_futures = self._file_system.Read(
|
| - set(paths) - set(fresh_data.iterkeys()),
|
| - skip_not_found=skip_not_found)
|
| - def resolve():
|
| - new_results = read_futures.Get()
|
| + def next(new_results):
|
| # Update the cache. This is a path -> (data, version) mapping.
|
| self._read_object_store.SetMulti(
|
| dict((path, (new_result, stat_futures[path].Get().version))
|
| for path, new_result in new_results.iteritems()))
|
| new_results.update(fresh_data)
|
| return new_results
|
| - return Future(callback=resolve)
|
| + # Read in the values that were uncached or old.
|
| + return self._file_system.Read(set(paths) - set(fresh_data.iterkeys()),
|
| + skip_not_found=skip_not_found).Then(next)
|
|
|
| def GetIdentity(self):
|
| return self._file_system.GetIdentity()
|
|
|