mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 14:58:37 +00:00
Merge pull request #1633 from KoLolX3/fix/world-build-case-lock
world_build: share locks across case and Unicode variants (WORLD-BUILD-CASE-LOCK)
This commit is contained in:
@ -105,6 +105,20 @@ class WorldBuildOutputLockTests(unittest.TestCase):
|
||||
self.assertFalse(os.path.exists(os.path.join(out, "world.json")))
|
||||
self.assertFalse(os.path.exists(os.path.join(out, "chunks")))
|
||||
|
||||
def test_case_and_unicode_variants_share_a_lock(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
out = os.path.join(tmp, "Wörld")
|
||||
alias = os.path.join(tmp, "wo\u0308RLD")
|
||||
unrelated = os.path.join(tmp, "other")
|
||||
with _lock_held_by_child(tmp, out):
|
||||
with self.assertRaisesRegex(RuntimeError, "another world_build is using"):
|
||||
with wb._exclusive_output(alias):
|
||||
pass
|
||||
with wb._exclusive_output(unrelated):
|
||||
pass
|
||||
with wb._exclusive_output(alias):
|
||||
pass
|
||||
|
||||
def test_short_name_spelling_of_a_held_output_is_refused(self):
|
||||
if os.name != "nt":
|
||||
self.skipTest("8.3 short names are Windows only")
|
||||
|
||||
@ -38,6 +38,7 @@ import stat
|
||||
import statistics
|
||||
import sys
|
||||
import tempfile
|
||||
import unicodedata
|
||||
|
||||
try:
|
||||
import fcntl
|
||||
@ -1272,9 +1273,12 @@ def _exclusive_output(out_dir: str):
|
||||
# and a successful one must contain only chunks/ and world.json. Key it on the resolved
|
||||
# path so every spelling of one folder (8.3 names, junctions, symlinks) shares a lock; for
|
||||
# a folder that does not exist yet, realpath resolves the part that does and appends the rest.
|
||||
key = hashlib.sha256(
|
||||
os.path.normcase(os.path.realpath(out_dir)).encode("utf-8", "surrogatepass")
|
||||
).hexdigest()[:20]
|
||||
# Fold conservatively on every platform: the output volume may ignore case or
|
||||
# Unicode normalization even when os.path.normcase does not (APFS, for example).
|
||||
# Distinct folders that fold alike can contend, but cannot publish concurrently.
|
||||
resolved = os.path.normcase(os.path.realpath(out_dir))
|
||||
lock_name = unicodedata.normalize("NFD", unicodedata.normalize("NFD", resolved).casefold())
|
||||
key = hashlib.sha256(lock_name.encode("utf-8", "surrogatepass")).hexdigest()[:20]
|
||||
lock_path = os.path.join(tempfile.gettempdir(), _WORLD_BUILD_LOCK + key)
|
||||
with open(lock_path, "a+b") as fh:
|
||||
fd = fh.fileno()
|
||||
|
||||
Reference in New Issue
Block a user