Provide better errors for failures to clear the apt cache
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 with a try/except and providing a useful and actionable error message.
You can reproduce this with:
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.
@mr-cal Hey, how do I clean the APT cache to get back in the normal modus
@lupaulus Try sudo rm -r ~/.cache/snapcraft/stage-packages/
You might have to delete the ~/.cache/snapcraft dir.
You might have to delete the
~/.cache/snapcraftdir.
Yeah, back on track ! Don't forget to remove the root generated .snap, prime and stage folders