OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 | 6 |
7 from file_system import FileSystem, FileNotFoundError | 7 from file_system import FileSystem, FileNotFoundError |
8 from future import Future | 8 from future import Future |
9 from test_file_system import _List, _StatTracker, TestFileSystem | 9 from test_file_system import _List, _StatTracker, TestFileSystem |
10 from path_util import IsDirectory | 10 from path_util import IsDirectory |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 # | 36 # |
37 # FileSystem implementation. | 37 # FileSystem implementation. |
38 # | 38 # |
39 | 39 |
40 def Read(self, paths, skip_not_found=False): | 40 def Read(self, paths, skip_not_found=False): |
41 '''Reads |paths| from |_file_system|, then applies the most recent update | 41 '''Reads |paths| from |_file_system|, then applies the most recent update |
42 from |_updates|, if any. | 42 from |_updates|, if any. |
43 ''' | 43 ''' |
44 self._read_count += 1 | 44 self._read_count += 1 |
45 future_result = self._file_system.Read(paths, skip_not_found=skip_not_found) | 45 def next(result): |
46 def resolve(): | |
47 self._read_resolve_count += 1 | 46 self._read_resolve_count += 1 |
48 result = future_result.Get() | |
49 for path in result.iterkeys(): | 47 for path in result.iterkeys(): |
50 update = self._GetMostRecentUpdate(path) | 48 update = self._GetMostRecentUpdate(path) |
51 if update is not None: | 49 if update is not None: |
52 result[path] = update | 50 result[path] = update |
53 return result | 51 return result |
54 return Future(callback=resolve) | 52 return self._file_system.Read(paths, |
| 53 skip_not_found=skip_not_found).Then(next) |
55 | 54 |
56 def Refresh(self): | 55 def Refresh(self): |
57 return self._file_system.Refresh() | 56 return self._file_system.Refresh() |
58 | 57 |
59 def _GetMostRecentUpdate(self, path): | 58 def _GetMostRecentUpdate(self, path): |
60 '''Returns the latest update for the file at |path|, or None if |path| | 59 '''Returns the latest update for the file at |path|, or None if |path| |
61 has never been updated. | 60 has never been updated. |
62 ''' | 61 ''' |
63 for update in reversed(self._updates): | 62 for update in reversed(self._updates): |
64 try: | 63 try: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 self._read_resolve_count = 0 | 123 self._read_resolve_count = 0 |
125 self._stat_count = 0 | 124 self._stat_count = 0 |
126 | 125 |
127 def Update(self, update): | 126 def Update(self, update): |
128 self._updates.append(TestFileSystem(update)) | 127 self._updates.append(TestFileSystem(update)) |
129 for path in _List(update).iterkeys(): | 128 for path in _List(update).iterkeys(): |
130 # Any files (not directories) which changed are now at the version | 129 # Any files (not directories) which changed are now at the version |
131 # derived from |_updates|. | 130 # derived from |_updates|. |
132 if not IsDirectory(path): | 131 if not IsDirectory(path): |
133 self._stat_tracker.SetVersion(path, len(self._updates)) | 132 self._stat_tracker.SetVersion(path, len(self._updates)) |
OLD | NEW |