From 658241d3bec97fd41828ed522a976775d8c7ddc9 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 31 May 2020 21:29:47 +0800 Subject: [PATCH] [gnucash-commands] don't force open a locked datafile qof_session_begin (..., ..., ignore_lock=TRUE, ..., ...) will force-open a datafile currently in use in another session. This will unfortunately delete any existing .LCK file. To my knowledge there is no read-only qofsession which will leave .LCK file intact. Therefore to prevent possible dataloss, it is best to disallow opening a locked file which prevents deletion of .LCK file. --- gnucash/gnucash-commands.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp index 638c4c25aa..2b6dd2f3dc 100644 --- a/gnucash/gnucash-commands.cpp +++ b/gnucash/gnucash-commands.cpp @@ -168,9 +168,12 @@ scm_run_report (void *data, if (!session) scm_cleanup_and_exit_with_failure (session); - qof_session_begin (session, datafile, TRUE, FALSE, FALSE); + qof_session_begin (session, datafile, FALSE, FALSE, FALSE); if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR) + { + fprintf (stderr, "ERROR: datafile not found, or locked in another session\n"); scm_cleanup_and_exit_with_failure (session); + } qof_session_load (session, report_session_percentage); if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)