Skip to content

Commit

Permalink
Check if existing database files are writable for us
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryforce committed Dec 31, 2024
1 parent 71233fe commit 2273ce5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -4185,6 +4185,32 @@ dt_database_t *dt_database_init(const char *alternative, const gboolean load_dat
else
snprintf(dbfilename_data, sizeof(dbfilename_data), ":memory:");

// It may happen that we will not have write access to the database restored
// from a backup or snapshot. Running darktable with a database that cannot
// be written to may result in incorrect operation, the cause of which will
// be difficult to diagnose. Let's check if we can continue.
char *readonly_db_text = g_markup_printf_escaped(
_("you do not have write access to at least one of the darktable databases:\n"
"\n"
"<span style='italic'>%s</span>\n"
"<span style='italic'>%s</span>\n"
"\n"
"please fix this and then run darktable again"),
dbfilename_library,
dbfilename_data);
if((access(dbfilename_library, F_OK) == 0 && access(dbfilename_library, W_OK) != 0)
|| (access(dbfilename_data, F_OK) == 0 && access(dbfilename_data, W_OK) != 0))
{
dt_print(DT_DEBUG_ALWAYS, "at least one of the dt databases (%s, %s) is not writeable",
dbfilename_library, dbfilename_data);
if(has_gui)
dt_gui_show_standalone_yes_no_dialog(_("darktable - read-only database detected"),
readonly_db_text,
_("_quit darktable"),
NULL);
exit(1);
}

/* create database */
dt_database_t *db = g_malloc0(sizeof(dt_database_t));
db->dbfilename_data = g_strdup(dbfilename_data);
Expand Down

0 comments on commit 2273ce5

Please sign in to comment.