Read/write permissions for Documents directory

Hello all!

I’m developing a note-taking application with Electron which I would like to publish on the Snapstore when ready.

Originally, I was storing notes in the SNAP_USER_COMMON directory, however, then I discovered that if someone removes the Snap from their system, all of their note data would be deleted too, which is potentially not what they would want.

Because of this, I’ve decided it is probably best to store the notes somewhere more visible, like in a users Documents directory within their home (/home/winterdj/Documents/notes for example), and so that if the snap is uninstalled, their notes are preserved, and they can delete if they choose too.

Based on everything I’ve read, it seems that that would involve the Snap needing the personal-files interface so that it would be able to read/write from that directory. And also, that interface would not auto-connect when installed.

Is there a way I can locally install a Snap with --dangerous but with the confinements and interface restrictions in place, as if someone had installed via the Snapstore? I’ve tried --dangerous --jailmode but with no success.

Also, my thinking is that asking a user to manually connect the interface after install in order for the app to be able to read/write notes is not going to be a great user experience. So after some more reading, I saw that I can make a request on this forum to have the personal-files interface auto-connect specifically for my snap?

I’d appreciate any guidance/advice around being able to read/write files from a directory within a users home directory. I’m quite new to Snap development, so all of the above is what I have so far pieced together from documentation and various forum posts.

Hi @winterdj, the right interface to use for this is home - it will give you access to the user’s $HOME (except for hidden files and directories).

That said, if your notes are not human-readable, it may still be a good idea to keep them in your $SNAP_USER_DATA or $SNAP_USER_COMMON. The former is preferred as it allows for data migration and snap reverts in case of trouble. Both of those are also part of the snap save snapshotting functionality - your users’ data isn’t lost on a plain snap remove, a snapshot is created on removal (see it with snap saved) and can be recovered with snap restore.

Thanks so much for the quick reply!

The files are in plain text, so they can be used with any application really.

I thought that home only gave read only permissions. Re-reading that again now though, it seems it would give me the read/write permissions to the directory with Documents. So that’s fantastic.

Though the docs say it is only auto-connected on classic? Does that mean classic confinement? Would I have the issue of users needing to manually connect the home interface after an install?

No, on classic distros, as opposed to Ubuntu Core. Still, I would reconsider the snap directories for the reasons stated above. Your users’ data is actually safer there.

1 Like