| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 - If |skip_not_found| is True, the resulting object will not contain any | 77 - If |skip_not_found| is True, the resulting object will not contain any |
| 78 mapping for that path. | 78 mapping for that path. |
| 79 - Otherwise, and by default, a FileNotFoundError is raised. This is | 79 - Otherwise, and by default, a FileNotFoundError is raised. This is |
| 80 guaranteed to only happen once the Future has been resolved (Get() | 80 guaranteed to only happen once the Future has been resolved (Get() |
| 81 called). | 81 called). |
| 82 | 82 |
| 83 For any other failure, raises a FileSystemError. | 83 For any other failure, raises a FileSystemError. |
| 84 ''' | 84 ''' |
| 85 raise NotImplementedError(self.__class__) | 85 raise NotImplementedError(self.__class__) |
| 86 | 86 |
| 87 def ReadSingle(self, path): | 87 def ReadSingle(self, path, skip_not_found=False): |
| 88 '''Reads a single file from the FileSystem. Returns a Future with the same | 88 '''Reads a single file from the FileSystem. Returns a Future with the same |
| 89 rules as Read(). If |path| is not found raise a FileNotFoundError on Get(). | 89 rules as Read(). If |path| is not found raise a FileNotFoundError on Get(). |
| 90 ''' | 90 ''' |
| 91 AssertIsValid(path) | 91 AssertIsValid(path) |
| 92 read_single = self.Read([path]) | 92 read_single = self.Read([path], skip_not_found=skip_not_found) |
| 93 return Future(callback=lambda: read_single.Get()[path]) | 93 return Future(callback=lambda: read_single.Get().get(path, None)) |
| 94 | 94 |
| 95 def Exists(self, path): | 95 def Exists(self, path): |
| 96 '''Returns a Future to the existence of |path|; True if |path| exists, | 96 '''Returns a Future to the existence of |path|; True if |path| exists, |
| 97 False if not. This method will not throw a FileNotFoundError unlike | 97 False if not. This method will not throw a FileNotFoundError unlike |
| 98 the Read* methods, however it may still throw a FileSystemError. | 98 the Read* methods, however it may still throw a FileSystemError. |
| 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) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 self.GetIdentity() == other.GetIdentity()) | 194 self.GetIdentity() == other.GetIdentity()) |
| 195 | 195 |
| 196 def __ne__(self, other): | 196 def __ne__(self, other): |
| 197 return not (self == other) | 197 return not (self == other) |
| 198 | 198 |
| 199 def __repr__(self): | 199 def __repr__(self): |
| 200 return '<%s>' % type(self).__name__ | 200 return '<%s>' % type(self).__name__ |
| 201 | 201 |
| 202 def __str__(self): | 202 def __str__(self): |
| 203 return repr(self) | 203 return repr(self) |
| OLD | NEW |