mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
mesh_compute_vs: restore write mode before unlink on replace failure and publish mode (MESH-COMPUTE-VS-STAGE-CLEANUP)
Apply published_mode(spv) to temporary staged SPV before atomic replacement, and restore write permission (0o600) before directory cleanup in exception block when replace fails, preventing Windows PermissionError [WinError 5] and stranded temporary files. agent: yes AI-assisted: yes
This commit is contained in:
@ -273,6 +273,32 @@ class Cli(unittest.TestCase):
|
||||
self.assertEqual(len(stderr.splitlines()), 1)
|
||||
self.assertIn("Permission denied", stderr)
|
||||
|
||||
def test_stage_cleanup_restores_write_mode_on_replace_failure(self):
|
||||
chmod_calls = []
|
||||
real_chmod = os.chmod
|
||||
|
||||
def track_chmod(path, mode, *args, **kwargs):
|
||||
chmod_calls.append((str(path), mode))
|
||||
return real_chmod(path, mode, *args, **kwargs)
|
||||
|
||||
def fake_run(cmd, *args, **kwargs):
|
||||
if cmd[0] == "spirv-as":
|
||||
with open(cmd[cmd.index("-o") + 1], "wb") as f:
|
||||
f.write(b"spv binary")
|
||||
return mock.Mock(returncode=0, stdout="", stderr="")
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
write_index(tmp, {"ms_a": {"mesh_compute": layout(clip=1)}})
|
||||
|
||||
with mock.patch.object(vs, "tool_path", side_effect=lambda name: name), \
|
||||
mock.patch("subprocess.run", side_effect=fake_run), \
|
||||
mock.patch("os.replace", side_effect=OSError("replace failed")), \
|
||||
mock.patch("os.chmod", side_effect=track_chmod):
|
||||
with self.assertRaisesRegex(OSError, "replace failed"):
|
||||
vs.build_for_index(tmp)
|
||||
|
||||
self.assertTrue(any(mode == 0o600 for _, mode in chmod_calls), chmod_calls)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@ -28,6 +28,9 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from file_mode import published_mode
|
||||
|
||||
SUFFIX = ".mesh_vs" # <ms name>.mesh_vs.spvasm / .spv next to the mesh shader
|
||||
USER_SGPRS = 32 # push constants: s0..s31, heap base, code base, then the output address (rdna2spirv.py)
|
||||
PC_TAIL_SET = 1 # set/binding of rdna2spirv.py --pc-tail-ubo's uniform block (6 dwords with --mesh-compute)
|
||||
@ -317,7 +320,15 @@ def build_for_index(spirv_dir):
|
||||
r = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if r.returncode:
|
||||
raise RuntimeError(f"{name} failed for {asm}:\n{r.stdout}{r.stderr}")
|
||||
os.replace(staged_spv, spv)
|
||||
os.chmod(staged_spv, published_mode(spv))
|
||||
try:
|
||||
os.replace(staged_spv, spv)
|
||||
except BaseException:
|
||||
try:
|
||||
os.chmod(staged_spv, 0o600)
|
||||
except OSError:
|
||||
pass
|
||||
raise
|
||||
built.append(spv)
|
||||
return built
|
||||
|
||||
|
||||
Reference in New Issue
Block a user