canonical / canonical/charmcraft

Charmcraft snap thinks `/cache` is the cache directory if snapd doesn't set `SNAP_USER_COMMON`

Open
#2,012 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
89
Forks
107
Avg merge
3d 23h
Merged PRs (30d)
20

Description

### Bug Description

If snapd [fails to set `$SNAP_USER_COMMON](https://bugs.launchpad.net/snapd/+bug/2090938) in the environment, charmcraft gets `/cache` as its [`$XDG_CACHE_HOME`](https://github.com/canonical/charmcraft/blob/c13f20ae65b6a4d3657dcdd30b2f606ccae86163/snap/snapcraft.yaml#L63), which is generally not writable.

Related:
- https://bugs.launchpad.net/snapd/+bug/2090938
- https://github.com/canonical/operator-workflows/issues/496

### To Reproduce

With snapd 2.66.1:

```
echo '$SNAP/bin/python -c "from charmcraft import env; print(env.get_host_shared_cache_path())"' | PATH=/snap/bin /usr/bin/snap run --shell charmcraft
```

### Environment

```
$ snap version
snap 2.66.1+25.04
snapd 2.66.1+25.04
series 16
ubuntu 25.04
kernel 6.11.0-9-generic
```

### charmcraft.yaml

```yaml
n/a
```

### Relevant log output

```shell
See: https://github.com/canonical/k8s-operator/actions/runs/12143320826/job/33859924966
```

Contributor guide

Open the contributing guide

Research direction

Start with env.get_host_shared_cache_path() and the XDG_CACHE_HOME definition in snap/snapcraft.yaml at line 63. Reproduce the behavior with the snap shell command from the issue, then verify that the cache path remains writable when SNAP_USER_COMMON is absent instead of resolving to /cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.