Skip to content

Commit 58889f9

Browse files
authored
Fix false positive writability check on cache directory (#23049)
We were incorrectly reporting non-existent parent directories as non-writable. This was broken in #22801.
1 parent da54ee3 commit 58889f9

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

test/test_other.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15412,3 +15412,25 @@ def test_rust_integration_basics(self):
1541215412
return 0;
1541315413
}''')
1541415414
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])
15415+
15416+
@crossplatform
15417+
def test_create_cache_directory(self):
15418+
if config.FROZEN_CACHE:
15419+
self.skipTest("test doesn't work with frozen cache")
15420+
15421+
# Test that the cache directory (including parent directories) is
15422+
# created on demand.
15423+
with env_modify({'EM_CACHE': os.path.abspath('foo/bar')}):
15424+
self.run_process([EMCC, '-c', test_file('hello_world.c')])
15425+
self.assertExists('foo/bar/sysroot_install.stamp')
15426+
15427+
if not WINDOWS:
15428+
# Test that we generate a nice error when we cannot create the cache
15429+
# because it is in a read-only location.
15430+
# For some reason this doesn't work on windows, at least not in CI.
15431+
os.mkdir('rodir')
15432+
os.chmod('rodir', 0o444)
15433+
self.assertFalse(os.access('rodir', os.W_OK))
15434+
with env_modify({'EM_CACHE': os.path.abspath('rodir/foo')}):
15435+
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
15436+
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy