Skip to content

Commit

Permalink
fix(provider): ensure /root/.cache exists (#2134)
Browse files Browse the repository at this point in the history
Fixes #2125
CRAFT-4037

Test failures are unrelated. I will be putting up a separate PR to fix
those. Reporter has confirmed that [the fix works for
them](#2125 (comment))
  • Loading branch information
lengau authored Feb 5, 2025
1 parent 2e34327 commit 9cc16dc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions charmcraft/services/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ def instance(
try:
# Use /root/.cache even if we're in the snap.
instance.execute_run(
["rm", "-rf", "/root/snap/charmcraft/common/cache"]
["rm", "-rf", "/root/snap/charmcraft/common/cache"], check=True
)
instance.execute_run(["mkdir", "-p", "/root/.cache"], check=True)
instance.execute_run(
["ln", "-s", "/root/.cache", "/root/snap/charmcraft/common/cache"]
["ln", "-s", "/root/.cache", "/root/snap/charmcraft/common/cache"],
check=True,
)
yield instance
finally:
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/services/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,30 @@ def test_locked_cache_no_cache(
)

assert not (tmp_path / "cache_cached").exists()


@pytest.mark.skipif(sys.platform == "win32", reason="no cache on windows")
@pytest.mark.skipif(
sys.platform == "darwin", reason="multipass sometimes fails weirdly for this test"
)
def test_cache_symlink(
service_factory: services.CharmcraftServiceFactory,
tmp_path: pathlib.Path,
default_build_info: BuildInfo,
emitter: RecordingEmitter,
):
cache_path = tmp_path / "cache"
cache_path.mkdir()
provider = service_factory.provider
provider_kwargs = {
"build_info": default_build_info,
"work_dir": tmp_path,
"cache_path": cache_path,
}
with provider.instance(**provider_kwargs) as instance:
instance.execute_run(["test", "-d", "/root/.cache"], check=True)
instance.execute_run(
["test", "-d", "/root/snap/charmcraft/common/cache"], check=True
)
with pytest.raises(subprocess.CalledProcessError):
instance.execute_run(["test", "-d", "/blorp"], check=True)

0 comments on commit 9cc16dc

Please sign in to comment.