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 Jan 1, 2025
1 parent 71233fe commit bf1fe6e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/common/database.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2011-2024 darktable developers.
Copyright (C) 2011-2025 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -4185,6 +4185,34 @@ 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.
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)
{
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);
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 bf1fe6e

Please sign in to comment.