Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions tests/test_awc_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,43 @@ def test_a_scanned_directory_with_no_bank_still_reports_empty(self):
self.assertIn("0 banks, 0 streams, 0 streamed-music channels", p.stderr)
self.assertEqual(p.stdout.splitlines()[0], ",".join(HEADER))

def test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly(self):
path = os.path.join(self.tmp.name, "manifest.json")
with open(path, "w", encoding="utf-8") as f:
f.write('{"initial": 1}\n')
os.chmod(path, 0o444)

real_unlink = os.unlink

def windows_strict_unlink(p):
mode = os.stat(p).st_mode
if not (mode & 0o200):
raise PermissionError(13, f"Access is denied: {p}")
return real_unlink(p)

with mock.patch.object(awc_manifest, "replace_retry", side_effect=OSError(13, "Permission denied")), \
mock.patch("os.unlink", side_effect=windows_strict_unlink):
with self.assertRaises(OSError):
awc_manifest.write_manifest([], 0, 0, "json", path)

leftover = [f for f in os.listdir(self.tmp.name) if f.startswith(".awc_manifest-")]
self.assertEqual(leftover, [])

def test_publish_applies_published_mode_on_windows(self):
path = os.path.join(self.tmp.name, "manifest_win.json")
chmod_calls = []
real_chmod = os.chmod

def track_chmod(p, mode):
chmod_calls.append((str(p), mode))
real_chmod(p, mode)

with mock.patch("os.name", "nt"), \
mock.patch.object(awc_manifest, "published_mode", return_value=0o640), \
mock.patch("os.chmod", side_effect=track_chmod):
awc_manifest.write_manifest([], 0, 0, "json", path)
self.assertTrue(any(".awc_manifest-" in p and mode == 0o640 for p, mode in chmod_calls), chmod_calls)


if __name__ == "__main__":
unittest.main(verbosity=2)
3 changes: 1 addition & 2 deletions tools/awc_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ def _emit(f):
try:
with staged:
_emit(staged)
if os.name != "nt":
os.chmod(staged.name, published_mode(destination))
os.chmod(staged.name, published_mode(destination))
replace_retry(staged.name, destination)
finally:
# The staging file may have inherited a read-only destination's mode; make it deletable
Expand Down
Loading