cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

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

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

CtrlXplorer
Established Member

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?

2 REPLIES 2

Sgilk
Contributor

Hello @CtrlXplorer ,

Are you also using the solutions content interface? I'm surprised you are even able to create the directory on your install hook. This is not the intended process and is also probably why you are unable to remove the directory in your uninstall hook. As this directory is outside of your snap, you will not have permissions to modify it. Snaps run in a confined sandboxed environment and are designed to only allow external interaction through plugs and slots.

See the SDK documentation on Persisting Configurations for information on working with the solutions content interface.

CtrlXplorer
Established Member

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:

CtrlXplorer_0-1708420208813.png

Have a nice day!

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist