snapcraft icon indicating copy to clipboard operation
snapcraft copied to clipboard

Provide better errors for failures to clear the apt cache

Open mr-cal opened this issue 1 year ago • 4 comments

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 avatar Feb 02 '24 20:02 mr-cal

@mr-cal Hey, how do I clean the APT cache to get back in the normal modus

lupaulus avatar Oct 02 '24 09:10 lupaulus

@lupaulus Try sudo rm -r ~/.cache/snapcraft/stage-packages/

mr-cal avatar Oct 02 '24 22:10 mr-cal

You might have to delete the ~/.cache/snapcraft dir.

mr-cal avatar Oct 02 '24 22:10 mr-cal

You might have to delete the ~/.cache/snapcraft dir.

Yeah, back on track ! Don't forget to remove the root generated .snap, prime and stage folders

lupaulus avatar Oct 04 '24 21:10 lupaulus