Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: chrome/common/extensions/docs/server2/caching_file_system.py

Issue 491653002: Docserver: Use GitilesFileSystem instead of SubversionFileSystem (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 All, Future 9 from future import All, Future
10 from path_util import AssertIsDirectory, IsDirectory, ToDirectory 10 from path_util import AssertIsDirectory, IsDirectory, ToDirectory
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 # constantly trying to read a file we now know doesn't exist. 134 # constantly trying to read a file we now know doesn't exist.
135 self._read_cache.SetMulti( 135 self._read_cache.SetMulti(
136 dict((path, (None, None)) for path in paths 136 dict((path, (None, None)) for path in paths
137 if stat_futures[path].Get() is None)) 137 if stat_futures[path].Get() is None))
138 new_results.update(up_to_date_data) 138 new_results.update(up_to_date_data)
139 return new_results 139 return new_results
140 # Read in the values that were uncached or old. 140 # Read in the values that were uncached or old.
141 return self._file_system.Read(set(paths) - set(up_to_date_data.iterkeys()), 141 return self._file_system.Read(set(paths) - set(up_to_date_data.iterkeys()),
142 skip_not_found=skip_not_found).Then(next) 142 skip_not_found=skip_not_found).Then(next)
143 143
144 def GetCommitID(self):
145 return self._file_system.GetCommitID()
146
147 def GetPreviousCommitID(self):
148 return self._file_system.GetPreviousCommitID()
149
144 def Walk(self, root, depth=-1): 150 def Walk(self, root, depth=-1):
145 '''Overrides FileSystem.Walk() to provide caching functionality. 151 '''Overrides FileSystem.Walk() to provide caching functionality.
146 ''' 152 '''
147 def file_lister(root): 153 def file_lister(root):
148 res, root_stat = All((self._walk_cache.Get(root), 154 res, root_stat = All((self._walk_cache.Get(root),
149 self.StatAsync(root))).Get() 155 self.StatAsync(root))).Get()
150 156
151 if res and res[2] == root_stat.version: 157 if res and res[2] == root_stat.version:
152 dirs, files = res[0], res[1] 158 dirs, files = res[0], res[1]
153 else: 159 else:
154 # Wasn't cached, or not up to date. 160 # Wasn't cached, or not up to date.
155 dirs, files = [], [] 161 dirs, files = [], []
156 for f in self.ReadSingle(root).Get(): 162 for f in self.ReadSingle(root).Get():
157 if IsDirectory(f): 163 if IsDirectory(f):
158 dirs.append(f) 164 dirs.append(f)
159 else: 165 else:
160 files.append(f) 166 files.append(f)
161 # Update the cache. This is a root -> (dirs, files, version) mapping. 167 # Update the cache. This is a root -> (dirs, files, version) mapping.
162 self._walk_cache.Set(root, (dirs, files, root_stat.version)) 168 self._walk_cache.Set(root, (dirs, files, root_stat.version))
163 return dirs, files 169 return dirs, files
164 return self._file_system.Walk(root, depth=depth, file_lister=file_lister) 170 return self._file_system.Walk(root, depth=depth, file_lister=file_lister)
165 171
166 def GetIdentity(self): 172 def GetIdentity(self):
167 return self._file_system.GetIdentity() 173 return self._file_system.GetIdentity()
168 174
169 def __repr__(self): 175 def __repr__(self):
170 return '%s of <%s>' % (type(self).__name__, repr(self._file_system)) 176 return '%s of <%s>' % (type(self).__name__, repr(self._file_system))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698