mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 08:58:36 +00:00
After the merge the tree held this branch's older states of files main maintains. Run against main's code, tests/test_acphal_abi.py and 11 of the 15 translator tests that differed failed, and the C++ runtime would have been built from two generations of its sources. So that the merge cannot break what main builds and tests: - runtime/ is main's, file for file (68 files only this branch had are not carried over); - every file under tools/, tests/ and docs/ that both sides have is main's (80 files); - ten translator tests only this branch has, which test rules main's translator does not have, and their fixtures are left out. What main gains: d3d12/ (the Rust D3D12 runtime), its launchers and helpers (Launcher.bat, scripts/play*.ps1, play-linux.sh, port_ctl.py, smooth-motion.ps1, fetch_vkd3d_proton.py, sync_victory.py), mods/example_lua, eleven notes under docs/, seven tools and the tests that pass with main's code, the README's sections and credits, and the "Runtime traps" section of AGENTS.md. Everything left out here is on the branch port/d3d12-nvidia. Checked: compileall; make_game.py --help; check_no_game_data.py over every file this adds to main; the line-ending, docs-encoding, CI-registration and docs tests; each test file that differs from main, on its own. Not run: the whole translator suite, the C++ build, cargo over d3d12/ after the merge (d3d12/ is byte for byte the branch's), CI. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
"""Permission bits for a file published through a private staging file.
|
|
|
|
tempfile.NamedTemporaryFile creates its file 0600, so a writer that stages next to the destination and then
|
|
os.replace()s it has to give the staged file the bits the destination would have had. Those are the bits of the
|
|
file it replaces, or, for a new file, what open() would give one in that directory.
|
|
|
|
The umask is not read with os.umask(0) / os.umask(mask): that sets process-wide state, so a thread creating a
|
|
file between the two calls gets mask 0 (#750 and #728 review). Instead a probe file is created with mode 0666 and
|
|
its bits are read back, which applies the current umask (and a directory's default ACL) without changing anything.
|
|
"""
|
|
import os
|
|
import secrets
|
|
import stat
|
|
|
|
|
|
def new_file_mode(directory):
|
|
"""The permission bits open() would give a new file in `directory`, found without touching the umask."""
|
|
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_BINARY", 0)
|
|
for _ in range(100):
|
|
probe = os.path.join(directory, f".mode-{secrets.token_hex(8)}.probe")
|
|
try:
|
|
fd = os.open(probe, flags, 0o666)
|
|
except FileExistsError:
|
|
continue
|
|
try:
|
|
return stat.S_IMODE(os.fstat(fd).st_mode)
|
|
finally:
|
|
os.close(fd)
|
|
try:
|
|
os.chmod(probe, 0o600)
|
|
os.remove(probe)
|
|
except OSError:
|
|
pass
|
|
raise FileExistsError(f"no free probe name in {directory}")
|
|
|
|
|
|
def published_mode(path):
|
|
"""The permission bits a file published at `path` should get: those of the file it replaces, or a new file's."""
|
|
try:
|
|
return stat.S_IMODE(os.stat(path).st_mode)
|
|
except FileNotFoundError:
|
|
return new_file_mode(os.path.dirname(os.path.abspath(path)))
|