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(CompiledFileSystem): | |
|
not at google - send to devlin
2013/05/11 20:39:53
comment
not at google - send to devlin
2013/05/11 20:39:53
pls always use composition not inheritance - parti
方觉(Fang Jue)
2013/05/12 03:01:47
Done.
方觉(Fang Jue)
2013/05/12 03:01:47
Done.
| |
| 9 class Factory(CompiledFileSystem.Factory): | |
| 10 def __init__(self, | |
| 11 file_system, | |
| 12 object_store_creator, | |
| 13 base_compiled_fs_factory=None): | |
| 14 self._file_system = file_system | |
| 15 self._object_store_creator = object_store_creator | |
| 16 self._base_compiled_fs_factory = base_compiled_fs_factory | |
| 17 | |
| 18 def Create(self, populate_function, cls, category=None): | |
| 19 fs = self._Create(populate_function, cls, category, | |
| 20 ChainedCompiledFileSystem) | |
| 21 fs._base_compiled_fs = self._base_compiled_fs_factory.Create( | |
| 22 populate_function, cls, category) | |
| 23 return fs | |
| 24 | |
|
not at google - send to devlin
2013/05/11 20:39:53
seems to me like this class could just as easily c
| |
| 25 def GetFromFile(self, path, binary=False): | |
| 26 # It's possible that a new file is added in this compiled file system | |
| 27 # and it doesn't exist in base_compiled_fs. | |
| 28 try: | |
| 29 version = self._file_system.Stat(path).version | |
| 30 cache_entry = self._base_compiled_fs._GetCacheEntryFromFile(path, | |
| 31 binary) | |
| 32 if version == cache_entry.version: | |
| 33 return cache_entry.cache_data | |
| 34 except FileNotFoundError: | |
| 35 pass | |
| 36 return CompiledFileSystem.GetFromFile(self, path, binary) | |
| 37 | |
| 38 def GetFromFileListing(self, path): | |
| 39 if not path.endswith('/'): | |
| 40 path += '/' | |
| 41 try: | |
| 42 version = self._file_system.Stat(path).version | |
| 43 cache_entry = self._base_compiled_fs._GetCacheEntryFromFileListing( | |
| 44 path) | |
| 45 if version == cache_entry.version: | |
| 46 return cache_entry.cache_data | |
| 47 except FileNotFoundError: | |
| 48 pass | |
| 49 return CompiledFileSystem.GetFromFileListing(self, path) | |
| OLD | NEW |