From 27892b7d36b3bcab5e2358793cd95502de16920a Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 15 Jun 2010 09:39:22 +0200 Subject: [PATCH] Check document health in sc_reload This hack checks if the PDF file is damaged when zathura tries to automatically reload it. Now even if the document is damaged, zathura does not close the current document session. --- zathura.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zathura.c b/zathura.c index 3fc8c96..c786167 100644 --- a/zathura.c +++ b/zathura.c @@ -1554,6 +1554,25 @@ sc_reload(Argument* argument) if(!Zathura.PDF.document) return; + /* check if file is damaged */ + char* file_uri = g_filename_to_uri(Zathura.PDF.file, NULL, NULL); + if(file_uri) + { + g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); + PopplerDocument* temporary_document = NULL; + if(!(temporary_document = poppler_document_new_from_file(file_uri, Zathura.PDF.password, NULL))) + { + g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + g_free(file_uri); + return; + } + g_static_mutex_unlock(&(Zathura.Lock.pdf_obj_lock)); + } + else + return; + + g_free(file_uri); + /* save old information */ g_static_mutex_lock(&(Zathura.Lock.pdf_obj_lock)); char* path = Zathura.PDF.file ? strdup(Zathura.PDF.file) : NULL;