upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonEyes <ducoinbenjamin@yahoo.fr>2026-11-28 20:40:14 +0100
committerGitHub <noreply@github.com>2026-11-28 20:40:14 +0100
commitda4fd4ea0bb687be9ffda5db7d2bebbe4e461a39 (patch)
tree7b247cc34e0ee6545a5138766be170d5df9dc1c6
parent4ce24c3499a41eb570b956e9f8e9a6606e507d70 (diff)
parentd1d01cb300153697859265d90619faf27555cafb (diff)
Merge pull request #1633 from KoLolX3/fix/world-build-case-lock
world_build: share locks across case and Unicode variants (WORLD-BUILD-CASE-LOCK)
-rw-r--r--tests/test_world_build_output_lock.py14
-rw-r--r--tools/world_build.py10
2 files changed, 21 insertions, 3 deletions
diff --git a/tests/test_world_build_output_lock.py b/tests/test_world_build_output_lock.py
index 7b461a2f7..52f11014c 100644
--- a/tests/test_world_build_output_lock.py
+++ b/tests/test_world_build_output_lock.py
@@ -105,6 +105,20 @@ class WorldBuildOutputLockTests(unittest.TestCase):
105 self.assertFalse(os.path.exists(os.path.join(out, "world.json"))) 105 self.assertFalse(os.path.exists(os.path.join(out, "world.json")))
106 self.assertFalse(os.path.exists(os.path.join(out, "chunks"))) 106 self.assertFalse(os.path.exists(os.path.join(out, "chunks")))
107 107
108 def test_case_and_unicode_variants_share_a_lock(self):
109 with tempfile.TemporaryDirectory() as tmp:
110 out = os.path.join(tmp, "Wörld")
111 alias = os.path.join(tmp, "wo\u0308RLD")
112 unrelated = os.path.join(tmp, "other")
113 with _lock_held_by_child(tmp, out):
114 with self.assertRaisesRegex(RuntimeError, "another world_build is using"):
115 with wb._exclusive_output(alias):
116 pass
117 with wb._exclusive_output(unrelated):
118 pass
119 with wb._exclusive_output(alias):
120 pass
121
108 def test_short_name_spelling_of_a_held_output_is_refused(self): 122 def test_short_name_spelling_of_a_held_output_is_refused(self):
109 if os.name != "nt": 123 if os.name != "nt":
110 self.skipTest("8.3 short names are Windows only") 124 self.skipTest("8.3 short names are Windows only")
diff --git a/tools/world_build.py b/tools/world_build.py
index 894c212fc..c67beed1d 100644
--- a/tools/world_build.py
+++ b/tools/world_build.py
@@ -38,6 +38,7 @@ import stat
38import statistics 38import statistics
39import sys 39import sys
40import tempfile 40import tempfile
41import unicodedata
41 42
42try: 43try:
43 import fcntl 44 import fcntl
@@ -1272,9 +1273,12 @@ def _exclusive_output(out_dir: str):
1272 # and a successful one must contain only chunks/ and world.json. Key it on the resolved 1273 # and a successful one must contain only chunks/ and world.json. Key it on the resolved
1273 # path so every spelling of one folder (8.3 names, junctions, symlinks) shares a lock; for 1274 # path so every spelling of one folder (8.3 names, junctions, symlinks) shares a lock; for
1274 # a folder that does not exist yet, realpath resolves the part that does and appends the rest. 1275 # a folder that does not exist yet, realpath resolves the part that does and appends the rest.
1275 key = hashlib.sha256( 1276 # Fold conservatively on every platform: the output volume may ignore case or
1276 os.path.normcase(os.path.realpath(out_dir)).encode("utf-8", "surrogatepass") 1277 # Unicode normalization even when os.path.normcase does not (APFS, for example).
1277 ).hexdigest()[:20] 1278 # Distinct folders that fold alike can contend, but cannot publish concurrently.
1279 resolved = os.path.normcase(os.path.realpath(out_dir))
1280 lock_name = unicodedata.normalize("NFD", unicodedata.normalize("NFD", resolved).casefold())
1281 key = hashlib.sha256(lock_name.encode("utf-8", "surrogatepass")).hexdigest()[:20]
1278 lock_path = os.path.join(tempfile.gettempdir(), _WORLD_BUILD_LOCK + key) 1282 lock_path = os.path.join(tempfile.gettempdir(), _WORLD_BUILD_LOCK + key)
1279 with open(lock_path, "a+b") as fh: 1283 with open(lock_path, "a+b") as fh:
1280 fd = fh.fileno() 1284 fd = fh.fileno()