How modify DataBase inside the snap using the same snap

Hello members, apologies if this topic was already discussed before, I am trying to update a DataBase that is contained inside a snap.

##snapcraft.yaml##

layout:
      /etc/folder/dataBase.db:
        bind-file: $SNAP_DATA/folder/dataBase.db

override-build: |
cp -f -r ${SDK_PREBUILD_PATH}/folder ${SNAPCRAFT_PART_INSTALL}

I am using a app contained in the snap too.

snap.updateDB

however I get this error
SQL error: attempt to write a readonly database

Also I have tried to edit the database using a external app but the file is read-only

Is it possbile to add this database like a writable file and can edit it using the snap-app?

you can use an install hook to copy it into teh right place, your override-build statement above just copies it to $SNAP/folder/ you want something in the install hook that copies it from $SNAP to $SNAP_DATA and then access it there …

Sorry I forgot put the line of the install file is this

#!/bin/sh -e

snapctl stop --disable ${SNAP_INSTANCE_NAME}

Copy database

cp -rf $SNAP/folder $SNAP_DATA

However I get the same error

note that $SNAP_DATA is under /var and root owned, to write to it from an app, this app will need to run as root (i.e. via sudo) or as a daemon …

Thank you, I solved the problem the layout is wrong I had this layout

layout:
/etc/folder/dataBase.db:
bind-file: $SNAP_DATA/folder/dataBase.db

but the link was incorrect the correct is symlink

layout:
/etc/folder/dataBase.db:
symlink: $SNAP_DATA/folder/dataBase.db

1 Like