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 sys | 5 import sys |
6 | 6 |
7 import schema_util | 7 import schema_util |
8 from docs_server_utils import ToUnicode | 8 from docs_server_utils import ToUnicode |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 from future import Future | 10 from future import Future |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 assert dir_name.startswith(path) | 178 assert dir_name.startswith(path) |
179 files += add_prefix(dir_name[len(path):], new_files) | 179 files += add_prefix(dir_name[len(path):], new_files) |
180 if dirs: | 180 if dirs: |
181 files += self._file_system.Read(dirs).Then( | 181 files += self._file_system.Read(dirs).Then( |
182 lambda results: get_from_future_listing(results)).Get() | 182 lambda results: get_from_future_listing(results)).Get() |
183 return files | 183 return files |
184 | 184 |
185 return self._file_system.Read(add_prefix(path, first_layer_dirs)).Then( | 185 return self._file_system.Read(add_prefix(path, first_layer_dirs)).Then( |
186 lambda results: first_layer_files + get_from_future_listing(results)) | 186 lambda results: first_layer_files + get_from_future_listing(results)) |
187 | 187 |
188 def GetFromFile(self, path): | 188 def GetFromFile(self, path, skip_not_found=False): |
189 '''Calls |compilation_function| on the contents of the file at |path|. If | 189 '''Calls |compilation_function| on the contents of the file at |path|. |
190 |binary| is True then the file will be read as binary - but this will only | 190 If |skip_not_found| is True, then None is passed to |compilation_function|. |
191 apply for the first time the file is fetched; if already cached, |binary| | |
192 will be ignored. | |
193 ''' | 191 ''' |
194 AssertIsFile(path) | 192 AssertIsFile(path) |
195 | 193 |
196 try: | 194 try: |
197 version = self._file_system.Stat(path).version | 195 version = self._file_system.Stat(path).version |
198 except FileNotFoundError: | 196 except FileNotFoundError: |
199 return Future(exc_info=sys.exc_info()) | 197 if skip_not_found: |
| 198 version = None |
| 199 else: |
| 200 return Future(exc_info=sys.exc_info()) |
200 | 201 |
201 cache_entry = self._file_object_store.Get(path).Get() | 202 cache_entry = self._file_object_store.Get(path).Get() |
202 if (cache_entry is not None) and (version == cache_entry.version): | 203 if (cache_entry is not None) and (version == cache_entry.version): |
203 return Future(value=cache_entry._cache_data) | 204 return Future(value=cache_entry._cache_data) |
204 | 205 |
205 def next(files): | 206 def compile_(files): |
206 cache_data = self._compilation_function(path, files) | 207 cache_data = self._compilation_function(path, files) |
207 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) | 208 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) |
208 return cache_data | 209 return cache_data |
209 return self._file_system.ReadSingle(path).Then(next) | 210 return self._file_system.ReadSingle( |
| 211 path, skip_not_found=skip_not_found).Then(compile_) |
210 | 212 |
211 def GetFromFileListing(self, path): | 213 def GetFromFileListing(self, path): |
212 '''Calls |compilation_function| on the listing of the files at |path|. | 214 '''Calls |compilation_function| on the listing of the files at |path|. |
213 Assumes that the path given is to a directory. | 215 Assumes that the path given is to a directory. |
214 ''' | 216 ''' |
215 AssertIsDirectory(path) | 217 AssertIsDirectory(path) |
216 | 218 |
217 try: | 219 try: |
218 version = self._file_system.Stat(path).version | 220 version = self._file_system.Stat(path).version |
219 except FileNotFoundError: | 221 except FileNotFoundError: |
(...skipping 20 matching lines...) Expand all Loading... |
240 cache_entry = self._list_object_store.Get(path).Get() | 242 cache_entry = self._list_object_store.Get(path).Get() |
241 if cache_entry is not None: | 243 if cache_entry is not None: |
242 return cache_entry.version | 244 return cache_entry.version |
243 return self._file_system.Stat(path).version | 245 return self._file_system.Stat(path).version |
244 | 246 |
245 def FileExists(self, path): | 247 def FileExists(self, path): |
246 return self._file_system.Exists(path) | 248 return self._file_system.Exists(path) |
247 | 249 |
248 def GetIdentity(self): | 250 def GetIdentity(self): |
249 return self._file_system.GetIdentity() | 251 return self._file_system.GetIdentity() |
OLD | NEW |