← Back to issue list

Provide better errors for failures to clear the apt cache

View original Github issue

Metadata

Project
snapcraft
Number
#4558
Type
issue
State
closed
Author
mr-cal
Labels
Status: Triaged Type: Enhancement
Created
Updated
Closed

Current evaluation

Closed as superseded: Snapcraft 8.14 added a warning for destructive-mode runs as non-root (craft-application#974) instead of an apt-cache error; legacy apt_cache code later removed.

Resolution: closed superseded

Reason: mr-cal closed the issue noting Snapcraft 8.14 shipped a related improvement that warns when running in destructive mode as a non-root user, implemented in canonical/craft-application#974 and documented in docs/release-notes/snapcraft-8-14.rst ("Destructive mode warning"). The originally proposed try/except around the legacy apt-cache clear never landed; snapcraft_legacy/internal/repo/apt_cache.py was deleted in commit ffb164b7a.

Evaluated by: mr-cal-bot

No scores available.

Issue body

### What needs to get done The apt cache may fail to be removed when snapcraft is run in destructive-mode as root, then not as root. Snapcraft should provide a better error for when the apt-cache cannot be removed. This can be done by wrapping [this block](https://github.com/snapcore/snapcraft/blob/89961cfc3a9f93b3fe551711e5a4f1e4f0ef3fa8/snapcraft_legacy/internal/repo/apt_cache.py#L120) with a try/except and providing a useful and actionable error message. You can reproduce this with: ```bash lxc launch ubuntu:22.04 repro-env lxc exec repro-env bash apt update apt install aptdaemon -y # to install /etc/apt/apt.conf.d/20dbus snap install snapcraft --classic su ubuntu cd ~ mkdir test-snap cd test-snap snapcraft init sed -i 's/core22/core20/g' snap/snapcraft.yaml echo " stage-packages: [curl]" >> snap/snapcraft.yaml snapcraft --destructive-mode snapcraft clean --destructive-mode sudo --preserve-env=HOME snapcraft --destructive-mode # --preserve-env=HOME not needed in ubuntu<19.10 sudo --preserve-env=HOME snapcraft clean --destructive-mode snapcraft --destructive-mode ``` Error: ``` Sorry, an error occurred in Snapcraft: [Errno 13] Permission denied: 'auth.conf.d' We would appreciate it if you anonymously reported this issue. No other data than the traceback and the version of snapcraft in use will be sent. ``` ### Why it needs to get done If snapcraft is run in destructive mode with sudo then without sudo, the error message doesn't help the user figure out how to clean their cache.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed superseded Closed as superseded: Snapcraft 8.14 added a warning for destructive-mode runs as non-root (craft-application#974) instead of an apt-cache error; legacy apt_cache code later removed.
stealth/space-bunny-alpha — closed superseded Superseded in Snapcraft 8.14 by a broader warning for non-root destructive-mode runs, added through canonical/craft-application#974.
stealth/space-bunny-alpha — closed superseded Closed as handled by a related change: craft-application PR #974 (commit 4b213f68), released in snapcraft 8.14, now warns when destructive-mode commands run as non-root. snapcraft_legacy apt_cache.py was also later deleted.
stealth/space-bunny-alpha — closed superseded Closed as superseded by Snapcraft 8.14, which added a warning for destructive-mode use as a non-root user via canonical/craft-application#974.
qwen/qwen3.6-35b-a3b — — Superseded by snapcraft 8.14, which now warns when running destructive mode as a non-root user. The related improvement was merged in canonical/craft-application#974, providing clearer guidance for cache permission issues.
qwen/qwen3.6-35b-a3b — — Closed as superseded by a related improvement in snapcraft 8.14. The application now warns when running in destructive mode as a non-root user, preventing the apt cache permission error. Resolved via canonical/craft-application#974.
qwen/qwen3.6-35b-a3b — — Closed and superseded. A related improvement was merged into snapcraft 8.14 via craft-application PR #974, which now warns when running destructive-mode as a non-root user, addressing the cache permission issue.
qwen3.6-35b-a3b-mtp-q6 — — Closed. A related improvement in snapcraft 8.14 via craft-application PR #974 now warns users when running in destructive-mode as a non-root user, preventing the apt cache permission error and removing the need for manual cleanup.

Update history

No update history recorded yet.

Related work

  • Superseded By: canonical/craft-application#974 (confidence 92%)

    Craft Application PR cited by the closing maintainer comment as the 8.14 improvement replacing this issue's request.

  • Likely Fixed By: snapcraft@ffb164b7a (confidence 55%)

    Commit 'chore: remove snapcraft_legacy' deleted the legacy apt_cache code the issue targeted.

Related issues

Issue Project State Summary Similarity
#3983 repo: raise error when populating the apt cache directory fails snapcraft merged Merged PR #3983 in commit 341037573, making Snapcraft raise a clear error when /etc/apt cannot be copied into its cache (CRAFT-1421).
74%
#648 Provide better errors for failures to clear the apt cache craft-parts open Enhancement request to wrap the apt cache rmtree in _populate_stage_cache_dir with try/except and raise an actionable error when the cache cannot be removed (e.g. sudo then non-sudo destructive runs). Still open, untriaged, tracked as CRAFT-2937.
73%