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|. If |
190 |binary| is True then the file will be read as binary - but this will only | 190 |binary| is True then the file will be read as binary - but this will only |
191 apply for the first time the file is fetched; if already cached, |binary| | 191 apply for the first time the file is fetched; if already cached, |binary| |
192 will be ignored. | 192 will be ignored. If |skip_not_found| is True, then if the file is not found |
193 None is passed to |compilation_function|. | |
193 ''' | 194 ''' |
194 AssertIsFile(path) | 195 AssertIsFile(path) |
195 | 196 |
196 try: | 197 try: |
197 version = self._file_system.Stat(path).version | 198 version = self._file_system.Stat(path).version |
198 except FileNotFoundError: | 199 except FileNotFoundError: |
199 return Future(exc_info=sys.exc_info()) | 200 if skip_not_found: |
201 version = None | |
202 else: | |
203 return Future(exc_info=sys.exc_info()) | |
200 | 204 |
201 cache_entry = self._file_object_store.Get(path).Get() | 205 cache_entry = self._file_object_store.Get(path).Get() |
202 if (cache_entry is not None) and (version == cache_entry.version): | 206 if (cache_entry is not None) and (version == cache_entry.version): |
203 return Future(value=cache_entry._cache_data) | 207 return Future(value=cache_entry._cache_data) |
204 | 208 |
205 def next(files): | 209 def next(files): |
206 cache_data = self._compilation_function(path, files) | 210 cache_data = self._compilation_function(path, files) |
207 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) | 211 self._file_object_store.Set(path, _CacheEntry(cache_data, version)) |
208 return cache_data | 212 return cache_data |
209 return self._file_system.ReadSingle(path).Then(next) | 213 return self._file_system.ReadSingle(path, skip_not_found).Then(next) |
not at google - send to devlin
2014/08/21 21:39:58
skip_not_found=skip_not_found
| |
210 | 214 |
211 def GetFromFileListing(self, path): | 215 def GetFromFileListing(self, path): |
212 '''Calls |compilation_function| on the listing of the files at |path|. | 216 '''Calls |compilation_function| on the listing of the files at |path|. |
213 Assumes that the path given is to a directory. | 217 Assumes that the path given is to a directory. |
214 ''' | 218 ''' |
215 AssertIsDirectory(path) | 219 AssertIsDirectory(path) |
216 | 220 |
217 try: | 221 try: |
218 version = self._file_system.Stat(path).version | 222 version = self._file_system.Stat(path).version |
219 except FileNotFoundError: | 223 except FileNotFoundError: |
(...skipping 20 matching lines...) Expand all Loading... | |
240 cache_entry = self._list_object_store.Get(path).Get() | 244 cache_entry = self._list_object_store.Get(path).Get() |
241 if cache_entry is not None: | 245 if cache_entry is not None: |
242 return cache_entry.version | 246 return cache_entry.version |
243 return self._file_system.Stat(path).version | 247 return self._file_system.Stat(path).version |
244 | 248 |
245 def FileExists(self, path): | 249 def FileExists(self, path): |
246 return self._file_system.Exists(path) | 250 return self._file_system.Exists(path) |
247 | 251 |
248 def GetIdentity(self): | 252 def GetIdentity(self): |
249 return self._file_system.GetIdentity() | 253 return self._file_system.GetIdentity() |
OLD | NEW |