(app_name: str)
| 292 | shutil.copy2(source_path, dest_path) |
| 293 | |
| 294 | def cleanup_tmp(app_name: str) -> bool: |
| 295 | try: |
| 296 | app_root = _get_app_root(app_name) |
| 297 | except ValueError as exc: |
| 298 | logger.exception("Error in cleanup_tmp: %s", exc) |
| 299 | return False |
| 300 | |
| 301 | try: |
| 302 | tmp_agent_root = _get_tmp_agent_root(app_root, app_name) |
| 303 | except ValueError as exc: |
| 304 | logger.exception("Error in cleanup_tmp: %s", exc) |
| 305 | return False |
| 306 | |
| 307 | try: |
| 308 | shutil.rmtree(tmp_agent_root) |
| 309 | except FileNotFoundError: |
| 310 | pass |
| 311 | except OSError as exc: |
| 312 | logger.exception("Error deleting tmp agent root: %s", exc) |
| 313 | return False |
| 314 | |
| 315 | tmp_dir = app_root / "tmp" |
| 316 | resolved_tmp_dir = tmp_dir.resolve() |
| 317 | if not resolved_tmp_dir.is_relative_to(app_root): |
| 318 | logger.error( |
| 319 | "Refusing to delete tmp outside app_root: %s", resolved_tmp_dir |
| 320 | ) |
| 321 | return False |
| 322 | |
| 323 | try: |
| 324 | tmp_dir.rmdir() |
| 325 | except OSError: |
| 326 | pass |
| 327 | |
| 328 | return True |
| 329 | |
| 330 | def ensure_tmp_exists(app_name: str) -> bool: |
| 331 | try: |
nothing calls this directly
no test coverage detected