Cache directories that already exist get an error
Metadata
Current evaluation
Fixed existing-cache crashes by replacing pyxdg with platformdirs in merged PR #169 (commit 6e66bbed).
Resolution: closed resolved
Reason: PR #169 was merged and commit 6e66bbed replaced pyxdg with platformdirs for cache-path handling, preventing exceptions when the cache directory already exists.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
When a cache directory already exists, pyxdg throws an exception that we don't catch
### To Reproduce
See: https://matrix.to/#/!LhFxJIPEcCacgdMghH:ubuntu.com/$kp5AKrB1uWyHgrnl5nFXH-plPE2PXgMpu_YCZLj56pw
### part yaml
_No response_
### Relevant log output
```shell
2024-01-02 11:27:02.019 Starting charmcraft
2024-01-02 11:27:02.022 Loading project file '/home/runner/work/istio-operators/istio-operators/charms/istio-gateway/charmcraft.yaml'
2024-01-02 11:27:02.023 Setting target machine to x86_64
2024-01-02 11:27:02.026 Running charmcraft:ubuntu-20.04-amd64 in amd64 instance...
2024-01-02 11:27:02.027 Preparing managed instance 'charmcraft-istio-gateway-on-amd64-for-amd64-779228'
2024-01-02 11:27:02.027 Using hostname 'charmcraft-istio-gateway-on-amd64-for-amd64-779228'
2024-01-02 11:27:02.027 Using default provider
2024-01-02 11:27:02.027 Launching managed ubuntu 20.04 instance...
2024-01-02 11:27:02.027 Executing on host: lxc remote list --format=yaml
2024-01-02 11:27:02.063 Executing on host: lxc remote add craft-com.ubuntu.cloud-buildd https://cloud-images.ubuntu.com/buildd/releases --protocol=simplestreams
2024-01-02 11:27:02.098 Remote 'craft-com.ubuntu.cloud-buildd' was successfully added.
2024-01-02 11:27:02.099 Executing on host: lxc project list local: --format=yaml
2024-01-02 11:27:02.139 Executing on host: lxc --project charmcraft project create local:charmcraft
2024-01-02 11:27:02.180 Executing on host: lxc --project default profile show local:default
2024-01-02 11:27:02.233 Executing on host: lxc --project charmcraft profile edit local:default
2024-01-02 11:27:02.285 Set LXD instance name to 'charmcraft-istio-gateway-on-amd64-for-amd64-779228'
2024-01-02 11:27:02.286 Checking for instance 'charmcraft-istio-gateway-on-amd64-for-amd64-779228' in project 'charmcraft' in remote 'local'
2024-01-02 11:27:02.286 Executing on host: lxc --project charmcraft list local: --format=yaml
2024-01-02 11:27:02.331 Instance 'charmcraft-istio-gateway-on-amd64-for-amd64-779228' does not exist.
2024-01-02 11:27:02.331 Set LXD instance name to 'base-instance-charmcraft-buildd-base-v4--b6028d8e72f849bc5897'
2024-01-02 11:27:02.331 Checking for base instance 'base-instance-charmcraft-buildd-base-v4--b6028d8e72f849bc5897' in project 'charmcraft' in remote 'local'
2024-01-02 11:27:02.332 Executing on host: lxc --project charmcraft list local: --format=yaml
2024-01-02 11:27:02.376 Base instance 'base-instance-charmcraft-buildd-base-v4--b6028d8e72f849bc5897' does not exist.
2024-01-02 11:27:02.376 Creating new instance from remote
2024-01-02 11:27:02.376 Creating new base instance from remote
2024-01-02 11:27:02.376 Creating new base instance from image 'core20' from remote 'craft-com.ubuntu.cloud-buildd'
2024-01-02 11:27:02.376 Executing on host: lxc --project charmcraft info local:
2024-01-02 11:27:02.451 Executing on host: lxc --project charmcraft launch craft-com.ubuntu.cloud-buildd:core20 local:base-instance-charmcraft-buildd-base-v4--b6028d8e72f849bc5897 --config 'raw.idmap=both 1001 0' --config security.syscalls.intercept.mknod=true --config user.craft_providers.status=STARTING --config user.craft_providers.timer=2024-01-02T11:27:02.451795+00:00 --config user.craft_providers.pid=16830
2024-01-02 11:27:02.019 Starting charmcraft
2024-01-02 11:27:02.020 charmcraft internal error: FileExistsError(17, 'File exists')
2024-01-02 11:27:02.022 Traceback (most recent call last):
2024-01-02 11:27:02.022 File "/snap/charmcraft/2180/lib/python3.10/site-packages/craft_application/application.py", line 375, in run
2024-01-02 11:27:02.022 self._configure_services(platform, build_for)
2024-01-02 11:27:02.022 File "/snap/charmcraft/2180/lib/python3.10/site-packages/charmcraft/application/main.py", line 107, in _configure_services
2024-01-02 11:27:02.022 cache_dir=self.cache_dir,
2024-01-02 11:27:02.022 File "/snap/charmcraft/2180/lib/python3.10/site-packages/craft_application/application.py", line 185, in cache_dir
2024-01-02 11:27:02.022 return save_cache_path(self.app.name) # type: ignore[no-any-return]
2024-01-02 11:27:02.022 File "/snap/charmcraft/2180/lib/python3.10/site-packages/xdg/BaseDirectory.py", line 84, in save_cache_path
2024-01-02 11:27:02.022 os.makedirs(path)
2024-01-02 11:27:02.022 File "/snap/charmcraft/2180/bin/../usr/lib/python3.10/os.py", line 225, in makedirs
2024-01-02 11:27:02.022 mkdir(name, mode)
2024-01-02 11:27:02.022 FileExistsError: [Errno 17] File exists: '/home/runner/snap/charmcraft/common/cache/charmcraft'
2024-01-02 11:27:02.022 Full execution log: '/home/runner/.local/state/charmcraft/log/charmcraft-20240102-112702.018439.log'
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed existing-cache crashes by replacing pyxdg with platformdirs in merged PR #169 (commit 6e66bbed). | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR #169 (commit 6e66bbed), replacing pyxdg with platformdirs for cache-path handling. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed. The uncaught FileExistsError triggered by pyxdg when cache directories already existed was fixed by updating directory creation logic to handle existing paths. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed. The uncaught FileExistsError in charmcraft when cache directories already exist was fixed. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/craft-application#169
(confidence 100%)
The merged PR directly replaced the failing pyxdg cache-path implementation.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #169 fix: use platformdirs replace pyxdg for cache path | craft-application | merged | Merged PR #169 (commit 6e66bbed, Jan 2024) swapped pyxdg for platformdirs to resolve the cache-directory creation race, closing #167. Application.cache_dir now returns a pathlib.Path via user_cache_path(..., ensure_exists=True). |