Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from compiled_file_system import CompiledFileSystem | |
| 6 from file_system import FileNotFoundError | |
| 7 | |
| 8 class ChainedCompiledFileSystem(object): | |
| 9 ''' A CompiledFileSystem implementation that fetches data from a chain of | |
| 10 CompiledFileSystems. | |
| 11 | |
| 12 The rules for the compiled file system chain are: | |
| 13 - Versions are fetched from the first compiled file system's underlying | |
| 14 file system. | |
| 15 - Each compiled file system is read in the reverse order (the last one is | |
| 16 read first). If the version matches, return the data. Otherwise, read | |
| 17 from the previous compiled file system until the first one is read. | |
| 18 | |
| 19 It is used to chain two compiled file systems whose underlying file systems | |
| 20 are slightly different. This makes it possible to reuse cached compiled data | |
|
not at google - send to devlin
2013/05/12 03:28:27
Nice comment, thanks.
But - s/two compiled file s
方觉(Fang Jue)
2013/05/12 04:22:07
Done.
| |
| 21 in one of them without recompiling everything that is shared by them. | |
| 22 ''' | |
| 23 class Factory(CompiledFileSystem.Factory): | |
| 24 def __init__(self, | |
| 25 factory_chain): | |
| 26 self._factory_chain = factory_chain | |
| 27 | |
| 28 def Create(self, populate_function, cls, category=None): | |
| 29 return ChainedCompiledFileSystem( | |
| 30 [factory.Create(populate_function, cls, category) | |
| 31 for factory in self._factory_chain]) | |
| 32 | |
| 33 def __init__(self, compiled_fs_chain): | |
| 34 assert len(compiled_fs_chain) > 0 | |
| 35 self._compiled_fs_chain = compiled_fs_chain | |
| 36 | |
| 37 def GetFromFile(self, path, binary=False): | |
| 38 # It's possible that a new file is added in the first compiled file system | |
| 39 # and it doesn't exist in other compiled file systems. | |
| 40 try: | |
| 41 version = self._compiled_fs_chain[0]._file_system.Stat(path).version | |
| 42 for compiled_fs in reversed(self._compiled_fs_chain): | |
| 43 cache_entry = compiled_fs._GetCacheEntryFromFile(path, binary) | |
|
not at google - send to devlin
2013/05/12 03:28:27
Is the version stuff necessary if you check them i
方觉(Fang Jue)
2013/05/12 04:22:07
Yes. It's necessary. version is used to determine
not at google - send to devlin
2013/05/12 05:11:41
Ok, never mind, I found a problem with what I was
| |
| 44 if cache_entry.version == version: | |
| 45 return cache_entry.cache_data | |
| 46 except FileNotFoundError: | |
| 47 pass | |
| 48 return self._compiled_fs_chain[0].GetFromFile(path, binary) | |
|
not at google - send to devlin
2013/05/12 03:28:27
Coud you add the comment here and below "Try first
方觉(Fang Jue)
2013/05/12 04:22:07
Done.
| |
| 49 | |
| 50 def GetFromFileListing(self, path): | |
| 51 if not path.endswith('/'): | |
| 52 path += '/' | |
| 53 try: | |
| 54 version = self._compiled_fs_chain[0]._file_system.Stat(path).version | |
| 55 for compiled_fs in reversed(self._compiled_fs_chain): | |
| 56 cache_entry = compiled_fs._GetCacheEntryFromFileListing(path) | |
| 57 if cache_entry.version == version: | |
| 58 return cache_entry.cache_data | |
| 59 except FileNotFoundError: | |
| 60 pass | |
| 61 return self._compiled_fs_chain[0].GetFromFileListing(path) | |
| OLD | NEW |