|
8 | 8 | import re
|
9 | 9 | import urllib.request
|
10 | 10 | from json.decoder import JSONDecodeError
|
11 |
| -from pathlib import Path |
| 11 | +from pathlib import Path, PurePosixPath |
12 | 12 | from typing import TYPE_CHECKING, Dict, List, Union, Tuple, Optional
|
13 | 13 |
|
14 | 14 | from crytic_compile.compilation_unit import CompilationUnit
|
@@ -147,23 +147,25 @@ def _handle_multiple_files(
|
147 | 147 |
|
148 | 148 | filtered_paths: List[str] = []
|
149 | 149 | for filename, source_code in source_codes.items():
|
150 |
| - path_filename = Path(filename) |
| 150 | + path_filename = PurePosixPath(filename) |
151 | 151 | if "contracts" in path_filename.parts and not filename.startswith("@"):
|
152 |
| - path_filename = Path(*path_filename.parts[path_filename.parts.index("contracts") :]) |
| 152 | + path_filename = PurePosixPath( |
| 153 | + *path_filename.parts[path_filename.parts.index("contracts") :] |
| 154 | + ) |
153 | 155 |
|
154 | 156 | # Convert "absolute" paths such as "/interfaces/IFoo.sol" into relative ones.
|
155 | 157 | # This is needed due to the following behavior from pathlib.Path:
|
156 | 158 | # > When several absolute paths are given, the last is taken as an anchor
|
157 | 159 | # We need to make sure this is relative, so that Path(directory, ...) remains anchored to directory
|
158 | 160 | if path_filename.is_absolute():
|
159 |
| - path_filename = Path(*path_filename.parts[1:]) |
| 161 | + path_filename = PurePosixPath(*path_filename.parts[1:]) |
160 | 162 |
|
161 |
| - filtered_paths.append(str(path_filename)) |
162 |
| - path_filename = Path(directory, path_filename) |
| 163 | + filtered_paths.append(path_filename.as_posix()) |
| 164 | + path_filename_disk = Path(directory, path_filename) |
163 | 165 |
|
164 |
| - if not os.path.exists(path_filename.parent): |
165 |
| - os.makedirs(path_filename.parent) |
166 |
| - with open(path_filename, "w", encoding="utf8") as file_desc: |
| 166 | + if not os.path.exists(path_filename_disk.parent): |
| 167 | + os.makedirs(path_filename_disk.parent) |
| 168 | + with open(path_filename_disk, "w", encoding="utf8") as file_desc: |
167 | 169 | file_desc.write(source_code["content"])
|
168 | 170 |
|
169 | 171 | return list(filtered_paths), directory
|
|
0 commit comments