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 from file_system import FileNotFoundError, FileSystem, StatInfo | 5 from file_system import FileNotFoundError, FileSystem, StatInfo |
6 from future import Future | 6 from future import Future |
| 7 from path_util import IsDirectory |
| 8 |
7 | 9 |
8 class EmptyDirFileSystem(FileSystem): | 10 class EmptyDirFileSystem(FileSystem): |
9 '''A FileSystem with empty directories. Useful to inject places to disable | 11 '''A FileSystem with empty directories. Useful to inject places to disable |
10 features such as samples. | 12 features such as samples. |
11 ''' | 13 ''' |
12 def Read(self, paths): | 14 def Read(self, paths): |
13 result = {} | 15 result = {} |
14 for path in paths: | 16 for path in paths: |
15 if not path.endswith('/'): | 17 if not IsDirectory(path): |
16 raise FileNotFoundError('EmptyDirFileSystem cannot read %s' % path) | 18 raise FileNotFoundError('EmptyDirFileSystem cannot read %s' % path) |
17 result[path] = [] | 19 result[path] = [] |
18 return Future(value=result) | 20 return Future(value=result) |
19 | 21 |
20 def Refresh(self): | 22 def Refresh(self): |
21 return Future(value=()) | 23 return Future(value=()) |
22 | 24 |
23 def Stat(self, path): | 25 def Stat(self, path): |
24 if not path.endswith('/'): | 26 if not IsDirectory(path): |
25 raise FileNotFoundError('EmptyDirFileSystem cannot stat %s' % path) | 27 raise FileNotFoundError('EmptyDirFileSystem cannot stat %s' % path) |
26 return StatInfo(0, child_versions=[]) | 28 return StatInfo(0, child_versions=[]) |
27 | 29 |
28 def GetIdentity(self): | 30 def GetIdentity(self): |
29 return self.__class__.__name__ | 31 return self.__class__.__name__ |
OLD | NEW |