canonical / snapcraft

Package, distribute, and update any app for Linux and IoT.
https://snapcraft.io
GNU General Public License v3.0
1.18k stars 444 forks source link

Provide better errors for failures to clear the apt cache #4558

Open mr-cal opened 8 months ago

mr-cal commented 8 months ago

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.

lupaulus commented 2 weeks ago

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

mr-cal commented 2 weeks ago

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

mr-cal commented 2 weeks ago

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

lupaulus commented 2 weeks ago

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

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