| 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 traceback | 6 import traceback |
| 7 | 7 |
| 8 from future import Future | 8 from future import Future |
| 9 from path_util import ( | 9 from path_util import ( |
| 10 AssertIsDirectory, AssertIsValid, IsDirectory, IsValid, SplitParent, | 10 AssertIsDirectory, AssertIsValid, IsDirectory, IsValid, SplitParent, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 There are several ways to implement this method via the interface but this | 100 There are several ways to implement this method via the interface but this |
| 101 method exists to do so in a canonical and most efficient way for caching. | 101 method exists to do so in a canonical and most efficient way for caching. |
| 102 ''' | 102 ''' |
| 103 AssertIsValid(path) | 103 AssertIsValid(path) |
| 104 if path == '': | 104 if path == '': |
| 105 # There is always a root directory. | 105 # There is always a root directory. |
| 106 return Future(value=True) | 106 return Future(value=True) |
| 107 | 107 |
| 108 parent, base = SplitParent(path) | 108 parent, base = SplitParent(path) |
| 109 list_future = self.ReadSingle(ToDirectory(parent)) | 109 def handle(error): |
| 110 def resolve(): | 110 if isinstance(error, FileNotFoundError): |
| 111 try: | |
| 112 return base in list_future.Get() | |
| 113 except FileNotFoundError: | |
| 114 return False | 111 return False |
| 115 return Future(callback=resolve) | 112 raise error |
| 113 return self.ReadSingle(ToDirectory(parent)).Then(lambda l: base in l, |
| 114 handle) |
| 116 | 115 |
| 117 def Refresh(self): | 116 def Refresh(self): |
| 118 '''Asynchronously refreshes the content of the FileSystem, returning a | 117 '''Asynchronously refreshes the content of the FileSystem, returning a |
| 119 future to its completion. | 118 future to its completion. |
| 120 ''' | 119 ''' |
| 121 raise NotImplementedError(self.__class__) | 120 raise NotImplementedError(self.__class__) |
| 122 | 121 |
| 123 # TODO(cduvall): Allow Stat to take a list of paths like Read. | 122 # TODO(cduvall): Allow Stat to take a list of paths like Read. |
| 124 def Stat(self, path): | 123 def Stat(self, path): |
| 125 '''Returns a |StatInfo| object containing the version of |path|. If |path| | 124 '''Returns a |StatInfo| object containing the version of |path|. If |path| |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 self.GetIdentity() == other.GetIdentity()) | 185 self.GetIdentity() == other.GetIdentity()) |
| 187 | 186 |
| 188 def __ne__(self, other): | 187 def __ne__(self, other): |
| 189 return not (self == other) | 188 return not (self == other) |
| 190 | 189 |
| 191 def __repr__(self): | 190 def __repr__(self): |
| 192 return '<%s>' % type(self).__name__ | 191 return '<%s>' % type(self).__name__ |
| 193 | 192 |
| 194 def __str__(self): | 193 def __str__(self): |
| 195 return repr(self) | 194 return repr(self) |
| OLD | NEW |