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 os | 5 import os |
6 import sys | 6 import sys |
7 | 7 |
8 from docs_server_utils import StringIdentity | 8 from docs_server_utils import StringIdentity |
9 from file_system import FileSystem, FileNotFoundError, StatInfo | 9 from file_system import FileSystem, FileNotFoundError, StatInfo |
10 from future import Future | 10 from future import Future |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return StatInfo(version, child_versions) | 62 return StatInfo(version, child_versions) |
63 except OSError as e: | 63 except OSError as e: |
64 raise FileNotFoundError('os.stat failed for %s: %s' % (path, e)) | 64 raise FileNotFoundError('os.stat failed for %s: %s' % (path, e)) |
65 | 65 |
66 | 66 |
67 class LocalFileSystem(FileSystem): | 67 class LocalFileSystem(FileSystem): |
68 '''FileSystem implementation which fetches resources from the local | 68 '''FileSystem implementation which fetches resources from the local |
69 filesystem. | 69 filesystem. |
70 ''' | 70 ''' |
71 def __init__(self, base_path): | 71 def __init__(self, base_path): |
| 72 # Enforce POSIX path, so path validity checks pass for Windows. |
| 73 base_path = base_path.replace(os.sep, '/') |
72 AssertIsDirectory(base_path) | 74 AssertIsDirectory(base_path) |
73 self._base_path = _ConvertToFilepath(base_path) | 75 self._base_path = _ConvertToFilepath(base_path) |
74 | 76 |
75 @staticmethod | 77 @staticmethod |
76 def Create(*path): | 78 def Create(*path): |
77 return LocalFileSystem(ChromiumPath(*path)) | 79 return LocalFileSystem(ChromiumPath(*path)) |
78 | 80 |
79 def Read(self, paths, skip_not_found=False): | 81 def Read(self, paths, skip_not_found=False): |
80 def resolve(): | 82 def resolve(): |
81 result = {} | 83 result = {} |
(...skipping 15 matching lines...) Expand all Loading... |
97 AssertIsValid(path) | 99 AssertIsValid(path) |
98 full_path = os.path.join(self._base_path, | 100 full_path = os.path.join(self._base_path, |
99 _ConvertToFilepath(path).lstrip(os.sep)) | 101 _ConvertToFilepath(path).lstrip(os.sep)) |
100 return _CreateStatInfo(full_path) | 102 return _CreateStatInfo(full_path) |
101 | 103 |
102 def GetIdentity(self): | 104 def GetIdentity(self): |
103 return '@'.join((self.__class__.__name__, StringIdentity(self._base_path))) | 105 return '@'.join((self.__class__.__name__, StringIdentity(self._base_path))) |
104 | 106 |
105 def __repr__(self): | 107 def __repr__(self): |
106 return 'LocalFileSystem(%s)' % self._base_path | 108 return 'LocalFileSystem(%s)' % self._base_path |
OLD | NEW |