(app_name: str)
| 227 | shutil.copy2(source_path, dest_path) |
| 228 | |
| 229 | def cleanup_tmp(app_name: str) -> bool: |
| 230 | try: |
| 231 | app_root = _get_app_root(app_name) |
| 232 | except ValueError as exc: |
| 233 | logger.exception("Error in cleanup_tmp: %s", exc) |
| 234 | return False |
| 235 | |
| 236 | try: |
| 237 | tmp_agent_root = _get_tmp_agent_root(app_root, app_name) |
| 238 | except ValueError as exc: |
| 239 | logger.exception("Error in cleanup_tmp: %s", exc) |
| 240 | return False |
| 241 | |
| 242 | try: |
| 243 | shutil.rmtree(tmp_agent_root) |
| 244 | except FileNotFoundError: |
| 245 | pass |
| 246 | except OSError as exc: |
| 247 | logger.exception("Error deleting tmp agent root: %s", exc) |
| 248 | return False |
| 249 | |
| 250 | tmp_dir = app_root / "tmp" |
| 251 | resolved_tmp_dir = tmp_dir.resolve() |
| 252 | if not resolved_tmp_dir.is_relative_to(app_root): |
| 253 | logger.error( |
| 254 | "Refusing to delete tmp outside app_root: %s", resolved_tmp_dir |
| 255 | ) |
| 256 | return False |
| 257 | |
| 258 | try: |
| 259 | tmp_dir.rmdir() |
| 260 | except OSError: |
| 261 | pass |
| 262 | |
| 263 | return True |
| 264 | |
| 265 | def ensure_tmp_exists(app_name: str) -> bool: |
| 266 | try: |
no test coverage detected