| 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 from file_system import FileSystem, StatInfo, FileNotFoundError | 5 from file_system import FileSystem, StatInfo, FileNotFoundError |
| 6 from future import Future | 6 from future import Future |
| 7 | 7 |
| 8 class _AsyncUncachedFuture(object): | 8 class _AsyncUncachedFuture(object): |
| 9 def __init__(self, | 9 def __init__(self, |
| 10 uncached, | 10 uncached, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 self._file_system = file_system | 33 self._file_system = file_system |
| 34 def create_object_store(category): | 34 def create_object_store(category): |
| 35 return (object_store_creator_factory.Create(CachingFileSystem) | 35 return (object_store_creator_factory.Create(CachingFileSystem) |
| 36 .Create(category='%s/%s' % (file_system.GetName(), category), | 36 .Create(category='%s/%s' % (file_system.GetName(), category), |
| 37 version=file_system.GetVersion())) | 37 version=file_system.GetVersion())) |
| 38 self._stat_object_store = create_object_store('stat') | 38 self._stat_object_store = create_object_store('stat') |
| 39 self._read_object_store = create_object_store('read') | 39 self._read_object_store = create_object_store('read') |
| 40 self._read_binary_object_store = create_object_store('read-binary') | 40 self._read_binary_object_store = create_object_store('read-binary') |
| 41 | 41 |
| 42 def Stat(self, path, stats=None): | 42 def Stat(self, path, stats=None): |
| 43 """Stats the directory given, or if a file is given, stats the files parent | 43 """Stats the directory given, or if a file is given, stats the file's parent |
| 44 directory to get info about the file. | 44 directory to get info about the file. |
| 45 """ | 45 """ |
| 46 # TODO(kalman): store the whole stat info, not just the version. | 46 # TODO(kalman): store the whole stat info, not just the version. |
| 47 version = self._stat_object_store.Get(path).Get() | 47 version = self._stat_object_store.Get(path).Get() |
| 48 if version is not None: | 48 if version is not None: |
| 49 return StatInfo(version) | 49 return StatInfo(version) |
| 50 | 50 |
| 51 # Always stat the parent directory, since it will have the stat of the child | 51 # Always stat the parent directory, since it will have the stat of the child |
| 52 # anyway, and this gives us an entire directory's stat info at once. | 52 # anyway, and this gives us an entire directory's stat info at once. |
| 53 if path.endswith('/'): | 53 if path.endswith('/'): |
| 54 dir_path = path | 54 dir_path = path |
| 55 else: | 55 else: |
| 56 dir_path = path.rsplit('/', 1)[0] + '/' | 56 dir_path = path.rsplit('/', 1)[0] + '/' |
| 57 | 57 |
| 58 dir_stat = self._file_system.Stat(dir_path) | 58 dir_stat = self._file_system.Stat(dir_path) |
| 59 if path == dir_path: | 59 if path == dir_path: |
| 60 version = dir_stat.version | 60 version = dir_stat.version |
| 61 else: | 61 else: |
| 62 version = dir_stat.child_versions.get(path.split('/')[-1], None) | 62 version = dir_stat.child_versions.get(path.split('/')[-1], None) |
| 63 if version is None: | 63 if version is None: |
| 64 raise FileNotFoundError(path) | 64 raise FileNotFoundError('Version was None for %s' % path) |
| 65 mapping = { path: version } | 65 mapping = { path: version } |
| 66 | 66 |
| 67 for child_path, child_version in dir_stat.child_versions.iteritems(): | 67 for child_path, child_version in dir_stat.child_versions.iteritems(): |
| 68 child_path = dir_path + child_path | 68 child_path = dir_path + child_path |
| 69 mapping[child_path] = child_version | 69 mapping[child_path] = child_version |
| 70 self._stat_object_store.SetMulti(mapping) | 70 self._stat_object_store.SetMulti(mapping) |
| 71 return StatInfo(version) | 71 return StatInfo(version) |
| 72 | 72 |
| 73 def Read(self, paths, binary=False): | 73 def Read(self, paths, binary=False): |
| 74 """Reads a list of files. If a file is in memcache and it is not out of | 74 """Reads a list of files. If a file is in memcache and it is not out of |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 result[path] = data | 96 result[path] = data |
| 97 | 97 |
| 98 if not uncached: | 98 if not uncached: |
| 99 return Future(value=result) | 99 return Future(value=result) |
| 100 | 100 |
| 101 return Future(delegate=_AsyncUncachedFuture( | 101 return Future(delegate=_AsyncUncachedFuture( |
| 102 self._file_system.Read(uncached, binary=binary), | 102 self._file_system.Read(uncached, binary=binary), |
| 103 result, | 103 result, |
| 104 self, | 104 self, |
| 105 read_object_store)) | 105 read_object_store)) |
| OLD | NEW |