|
1 | | -from typing import Literal, List, Tuple |
| 1 | +from typing import Literal, List, Tuple, Optional |
2 | 2 | import logging |
3 | 3 | import os |
4 | 4 | import weakref |
@@ -233,7 +233,7 @@ def validate_integration_type(integration_type: str) -> IntegrationType: |
233 | 233 | return integration_type # type: ignore |
234 | 234 |
|
235 | 235 | @staticmethod |
236 | | - def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100, base_path: str = None, base_paths: List[str] = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]: |
| 236 | + def load_files_for_sending_lazy(files: List[str], workspace: Optional[str] = None, max_open_files: int = 100, base_path: Optional[str] = None, base_paths: Optional[List[str]] = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]: |
237 | 237 | """ |
238 | 238 | Prepares files for sending to the Socket API using lazy loading. |
239 | 239 | |
@@ -268,78 +268,75 @@ def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_ope |
268 | 268 | # Normalize file path |
269 | 269 | if "\\" in file_path: |
270 | 270 | file_path = file_path.replace("\\", "/") |
271 | | - |
272 | | - for file_path in files: |
273 | | - # Normalize file path |
274 | | - if "\\" in file_path: |
275 | | - file_path = file_path.replace("\\", "/") |
276 | 271 |
|
277 | | - # Skip directories |
278 | | - if os.path.isdir(file_path): |
279 | | - continue |
| 272 | + # Skip directories |
| 273 | + if os.path.isdir(file_path): |
| 274 | + continue |
280 | 275 |
|
281 | | - # Handle file path splitting safely |
282 | | - if "/" in file_path: |
283 | | - _, name = file_path.rsplit("/", 1) |
284 | | - else: |
285 | | - name = file_path |
| 276 | + # Handle file path splitting safely |
| 277 | + if "/" in file_path: |
| 278 | + _, name = file_path.rsplit("/", 1) |
| 279 | + else: |
| 280 | + name = file_path |
286 | 281 |
|
287 | | - # Calculate the key name for the form data |
288 | | - key = file_path |
289 | | - path_stripped = False |
| 282 | + # Calculate the key name for the form data |
| 283 | + key = file_path |
| 284 | + path_stripped = False |
290 | 285 |
|
291 | | - # If base_paths is provided, try to strip one of the paths from the file path |
292 | | - if base_paths: |
293 | | - for bp in base_paths: |
294 | | - normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp |
295 | | - if key.startswith(normalized_base_path): |
296 | | - key = key[len(normalized_base_path):] |
297 | | - path_stripped = True |
298 | | - break |
299 | | - elif key.startswith(bp.rstrip("/")): |
300 | | - stripped_base = bp.rstrip("/") |
301 | | - if key.startswith(stripped_base + "/") or key == stripped_base: |
302 | | - key = key[len(stripped_base):] |
303 | | - key = key.lstrip("/") |
304 | | - path_stripped = True |
305 | | - break |
306 | | - elif base_path: |
307 | | - normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path |
| 286 | + # If base_paths is provided, try to strip one of the paths from the file path |
| 287 | + if base_paths: |
| 288 | + for bp in base_paths: |
| 289 | + normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp |
308 | 290 | if key.startswith(normalized_base_path): |
309 | 291 | key = key[len(normalized_base_path):] |
310 | 292 | path_stripped = True |
311 | | - elif key.startswith(base_path.rstrip("/")): |
312 | | - stripped_base = base_path.rstrip("/") |
| 293 | + break |
| 294 | + elif key.startswith(bp.rstrip("/")): |
| 295 | + stripped_base = bp.rstrip("/") |
313 | 296 | if key.startswith(stripped_base + "/") or key == stripped_base: |
314 | 297 | key = key[len(stripped_base):] |
315 | 298 | key = key.lstrip("/") |
316 | 299 | path_stripped = True |
317 | | - |
318 | | - # If workspace is provided and no base paths matched, fall back to workspace logic |
319 | | - if not path_stripped and workspace and file_path.startswith(workspace): |
320 | | - key = file_path[len(workspace):] |
321 | | - # Remove all leading slashes (for absolute paths) |
322 | | - while key.startswith("/"): |
323 | | - key = key[1:] |
| 300 | + break |
| 301 | + elif base_path: |
| 302 | + normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path |
| 303 | + if key.startswith(normalized_base_path): |
| 304 | + key = key[len(normalized_base_path):] |
324 | 305 | path_stripped = True |
| 306 | + elif key.startswith(base_path.rstrip("/")): |
| 307 | + stripped_base = base_path.rstrip("/") |
| 308 | + if key.startswith(stripped_base + "/") or key == stripped_base: |
| 309 | + key = key[len(stripped_base):] |
| 310 | + key = key.lstrip("/") |
| 311 | + path_stripped = True |
| 312 | + |
| 313 | + # If workspace is provided and no base paths matched, fall back to workspace logic |
| 314 | + if not path_stripped and workspace and file_path.startswith(workspace): |
| 315 | + key = file_path[len(workspace):] |
| 316 | + # Remove all leading slashes (for absolute paths) |
| 317 | + while key.startswith("/"): |
| 318 | + key = key[1:] |
| 319 | + path_stripped = True |
| 320 | + |
| 321 | + # Clean up relative path prefixes, but preserve filename dots |
| 322 | + while key.startswith("./"): |
| 323 | + key = key[2:] |
| 324 | + while key.startswith("../"): |
| 325 | + key = key[3:] |
| 326 | + # Remove any remaining leading slashes (for absolute paths) |
| 327 | + while key.startswith("/"): |
| 328 | + key = key[1:] |
325 | 329 |
|
326 | | - # Clean up relative path prefixes, but preserve filename dots |
327 | | - while key.startswith("./"): |
328 | | - key = key[2:] |
329 | | - while key.startswith("../"): |
330 | | - key = key[3:] |
331 | | - # Remove any remaining leading slashes (for absolute paths) |
| 330 | + # Remove Windows drive letter if present (C:/...) |
| 331 | + if len(key) > 2 and key[1] == ':' and (key[2] == '/' or key[2] == '\\'): |
| 332 | + key = key[2:] |
332 | 333 | while key.startswith("/"): |
333 | 334 | key = key[1:] |
334 | 335 |
|
335 | | - # Remove Windows drive letter if present (C:/...) |
336 | | - if len(key) > 2 and key[1] == ':' and (key[2] == '/' or key[2] == '\\'): |
337 | | - key = key[2:] |
338 | | - while key.startswith("/"): |
339 | | - key = key[1:] |
| 336 | + # Create lazy file loader instead of opening file immediately |
| 337 | + lazy_file = LazyFileLoader(file_path, key) |
| 338 | + payload = (key, (key, lazy_file)) |
| 339 | + send_files.append(payload) |
340 | 340 |
|
341 | | - # Create lazy file loader instead of opening file immediately |
342 | | - lazy_file = LazyFileLoader(file_path, key) |
343 | | - payload = (key, (key, lazy_file)) |
344 | | - send_files.append(payload) |
345 | | - return send_files |
| 341 | + log.debug(f"Prepared {len(send_files)} files for lazy loading") |
| 342 | + return send_files |
0 commit comments