Chromium Code Reviews| 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 posixpath | 5 import posixpath |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 from file_system import FileSystem, StatInfo, FileNotFoundError | 8 from file_system import FileSystem, StatInfo, FileNotFoundError |
| 9 from future import Future | 9 from future import Future |
| 10 from path_util import IsDirectory | 10 from path_util import IsDirectory, ToDirectory |
| 11 from third_party.json_schema_compiler.memoize import memoize | 11 from third_party.json_schema_compiler.memoize import memoize |
| 12 | 12 |
| 13 | 13 |
| 14 class CachingFileSystem(FileSystem): | 14 class CachingFileSystem(FileSystem): |
| 15 '''FileSystem which implements a caching layer on top of |file_system|. It's | 15 '''FileSystem which implements a caching layer on top of |file_system|. It's |
| 16 smart, using Stat() to decided whether to skip Read()ing from |file_system|, | 16 smart, using Stat() to decided whether to skip Read()ing from |file_system|, |
| 17 and only Stat()ing directories never files. | 17 and only Stat()ing directories never files. |
| 18 ''' | 18 ''' |
| 19 def __init__(self, file_system, object_store_creator): | 19 def __init__(self, file_system, object_store_creator): |
| 20 self._file_system = file_system | 20 self._file_system = file_system |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 36 def Stat(self, path): | 36 def Stat(self, path): |
| 37 return self.StatAsync(path).Get() | 37 return self.StatAsync(path).Get() |
| 38 | 38 |
| 39 def StatAsync(self, path): | 39 def StatAsync(self, path): |
| 40 '''Stats the directory given, or if a file is given, stats the file's parent | 40 '''Stats the directory given, or if a file is given, stats the file's parent |
| 41 directory to get info about the file. | 41 directory to get info about the file. |
| 42 ''' | 42 ''' |
| 43 # Always stat the parent directory, since it will have the stat of the child | 43 # Always stat the parent directory, since it will have the stat of the child |
| 44 # anyway, and this gives us an entire directory's stat info at once. | 44 # anyway, and this gives us an entire directory's stat info at once. |
| 45 dir_path, file_path = posixpath.split(path) | 45 dir_path, file_path = posixpath.split(path) |
| 46 if dir_path and not dir_path.endswith('/'): | 46 dir_path = ToDirectory(dir_path) |
|
ahernandez
2014/08/04 20:40:02
I had to add a few of these because the path '' wa
| |
| 47 dir_path += '/' | |
| 48 | 47 |
| 49 def make_stat_info(dir_stat): | 48 def make_stat_info(dir_stat): |
| 50 '''Converts a dir stat into the correct resulting StatInfo; if the Stat | 49 '''Converts a dir stat into the correct resulting StatInfo; if the Stat |
| 51 was for a file, the StatInfo should just contain that file. | 50 was for a file, the StatInfo should just contain that file. |
| 52 ''' | 51 ''' |
| 53 if path == dir_path: | 52 if path == dir_path: |
| 54 return dir_stat | 53 return dir_stat |
| 55 # Was a file stat. Extract that file. | 54 # Was a file stat. Extract that file. |
| 56 file_version = dir_stat.child_versions.get(file_path) | 55 file_version = dir_stat.child_versions.get(file_path) |
| 57 if file_version is None: | 56 if file_version is None: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 for path, new_result in new_results.iteritems())) | 131 for path, new_result in new_results.iteritems())) |
| 133 new_results.update(fresh_data) | 132 new_results.update(fresh_data) |
| 134 return new_results | 133 return new_results |
| 135 return Future(callback=resolve) | 134 return Future(callback=resolve) |
| 136 | 135 |
| 137 def GetIdentity(self): | 136 def GetIdentity(self): |
| 138 return self._file_system.GetIdentity() | 137 return self._file_system.GetIdentity() |
| 139 | 138 |
| 140 def __repr__(self): | 139 def __repr__(self): |
| 141 return '%s of <%s>' % (type(self).__name__, repr(self._file_system)) | 140 return '%s of <%s>' % (type(self).__name__, repr(self._file_system)) |
| OLD | NEW |