(
project_path: Path,
dest: Path,
content: bytes,
*,
mode: int = 0o644,
)
| 246 | |
| 247 | |
| 248 | def _write_shared_bytes( |
| 249 | project_path: Path, |
| 250 | dest: Path, |
| 251 | content: bytes, |
| 252 | *, |
| 253 | mode: int = 0o644, |
| 254 | ) -> None: |
| 255 | _ensure_safe_shared_destination(project_path, dest) |
| 256 | fd, temp_name = tempfile.mkstemp(prefix=f".{dest.name}.", dir=dest.parent) |
| 257 | temp_path = Path(temp_name) |
| 258 | try: |
| 259 | with os.fdopen(fd, "wb") as fh: |
| 260 | fh.write(content) |
| 261 | temp_path.chmod(mode) |
| 262 | _ensure_safe_shared_destination(project_path, dest) |
| 263 | os.replace(temp_path, dest) |
| 264 | finally: |
| 265 | if temp_path.exists(): |
| 266 | temp_path.unlink() |
| 267 | |
| 268 | |
| 269 | _BASH_FORMAT_COMMAND_RE = re.compile( |
no test coverage detected