How to define a path to save user data?

I’m writing a GNOME application using gtk-rs. Right now I’m using pure cargo to build, as in the tutorial Introduction - GUI development with Rust and GTK 4 , so no Flatpak, meson, … but I want to get into this stuff later. I am saving user data in an sqlite database. Right now, I have hardcoded the location of the database on my computer in the Rust source code.

However I know that the location should depend on the way the app is going to be installed, so it should be in .var/app/… if it’s installed via flatpak, or maybe in .local/share/… otherwise. What is the proper way to define a path that will work on all systems?

Also I wonder: Should the initial creation of the database be done when running my app for the first time, or should this be part of the installation process?

I would recommend using GLib.get_user_data_dir

Should the initial creation of the database be done when running my app for the first time, or should this be part of the installation process?

When your app runs – if someone removes files in your home you’ll want your app to still work.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.