Snap remove hook does not remove the app directory in the active configuration

Description: I have developed an snap app that includes both install and remove hooks. The install hook successfully creates a directory during installation, while the remove hook is supposed to remove this directory upon uninstallation. However, I'm encountering a problem where the remove hook fails to remove the directory due to insufficient permissions.

Here is how my working install script looks:

 

# Copies configuration file 'app.conf' into current 'Active Configuration'

APP_DIR=$SNAP_COMMON/solutions/activeConfiguration/my-app/app

if [ ! -d "$APP_DIR" ]; then 
   echo "Creating directory at $APP_DIR"
   mkdir -p $APP_DIR
fi

cp $SNAP/config/app.conf $APP_DIR/app.conf
chmod 666 $APP_DIR/app.conf

 


Here is my remove script (that doesn't work):

# Remove the active configuration directory
APP_DIR=$SNAP_COMMON/solutions/activeConfiguration/my-app

if [ -d "$APP_DIR" ]; then
  echo "Removing active configuration directory from $APP_DIR"

  if rm -rf "$APP_DIR"; then
      echo "Directory removed successfully"
  else
      echo "Failed to remove directory"
      exit 1 
  fi

else
  echo "Active configuration directory does not exist at $APP_DIR"
fi


The final output from the remove script is :
snap.d service: /snap/my-app/x1/meta/hooks/remove: 19: Permission denied
Failed to remove directory

 

Additional info:
- Build environment: Ubuntu 20.04
- Snap base: core20
- CtrlX Core Virtual version: 1.20.9
- CtrlX Works version: 1.20.5


How do I solve this issue this issue, why the $APP_DIR directory cannot be removed?

Best reply by CtrlXplorer

Hello Sgilk,

Thanks for your detailed insights and explanations!  I noticed that I already had the solutions content interface, but the remove hook was missing the plug towards the active-solution. My remove hook now has all the neccesary permissions to remove my app directory. I simply added the higlighted code below:

Have a nice day!

View original
2 replies