Skip to content

Commit b1013d1

Browse files
committed
Fix false positive writability check on cache directory
We were incorrectly reporting non-existent parent directories as non-writable. This was broken in #22801.
1 parent c47a0f8 commit b1013d1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

test/test_other.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15408,3 +15408,20 @@ def test_rust_integration_basics(self):
1540815408
return 0;
1540915409
}''')
1541015410
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])
15411+
15412+
@crossplatform
15413+
def test_create_cache_directory(self):
15414+
# Test that the cache directory (including parent directories) is
15415+
# created on demand.
15416+
with env_modify({'EM_CACHE': os.path.abspath('foo/bar')}):
15417+
self.run_process([EMCC, '-c', test_file('hello_world.c')])
15418+
self.assertExists('foo/bar/sysroot_install.stamp')
15419+
15420+
# Test that we generate a nice error when we cannot create the cache
15421+
# because it is in a read-only location.
15422+
os.mkdir('rodir')
15423+
os.chmod('rodir', 0o444)
15424+
self.assertFalse(os.access('rodir', os.W_OK))
15425+
with env_modify({'EM_CACHE': os.path.abspath('rodir/foo')}):
15426+
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
15427+
self.assertContained('emcc: error: unable to create cache directory', err)

tools/cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def lock(reason):
7575
def ensure():
7676
ensure_setup()
7777
if not os.path.isdir(cachedir):
78-
parent_dir = os.path.dirname(cachedir)
79-
if not is_writable(parent_dir):
80-
utils.exit_with_error(f'unable to create cache directory "{cachedir}": parent directory not writable (see https://emscripten.org/docs/tools_reference/emcc.html for info on setting the cache directory)')
81-
utils.safe_ensure_dirs(cachedir)
78+
try:
79+
utils.safe_ensure_dirs(cachedir)
80+
except Exception as e:
81+
utils.exit_with_error(f'unable to create cache directory "{cachedir}": {e} (see https://emscripten.org/docs/tools_reference/emcc.html for info on setting the cache directory)')
8282

8383

8484
def erase():

0 commit comments

Comments
 (0)