Also use SHA256 of documents to lookup fileinfo

This commit is contained in:
Sebastian Ramacher 2019-12-01 17:20:51 +01:00
parent f03e639560
commit af253296d9
5 changed files with 26 additions and 19 deletions

View file

@ -633,8 +633,8 @@ plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jum
} }
static bool static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* plain_set_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
file_info) zathura_fileinfo_t* file_info)
{ {
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db); ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb); ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
@ -663,8 +663,8 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
} }
static bool static bool
plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t* plain_get_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
file_info) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {
return false; return false;

View file

@ -649,7 +649,7 @@ sqlite_load_jumplist(zathura_database_t* db, const char* file)
} }
static bool static bool
sqlite_set_fileinfo(zathura_database_t* db, const char* file, sqlite_set_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {
@ -690,7 +690,7 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
} }
static bool static bool
sqlite_get_fileinfo(zathura_database_t* db, const char* file, sqlite_get_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
if (db == NULL || file == NULL || file_info == NULL) { if (db == NULL || file == NULL || file_info == NULL) {

View file

@ -52,21 +52,21 @@ zathura_db_save_jumplist(zathura_database_t* db, const char* file, girara_list_t
} }
bool bool
zathura_db_set_fileinfo(zathura_database_t* db, const char* file, zathura_db_set_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && hash_sha256 != NULL && file_info != NULL, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->set_fileinfo(db, file, file_info); return ZATHURA_DATABASE_GET_INTERFACE(db)->set_fileinfo(db, file, hash_sha256, file_info);
} }
bool bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file, zathura_db_get_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info) zathura_fileinfo_t* file_info)
{ {
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, false); g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && hash_sha256 != NULL && file_info != NULL, false);
return ZATHURA_DATABASE_GET_INTERFACE(db)->get_fileinfo(db, file, file_info); return ZATHURA_DATABASE_GET_INTERFACE(db)->get_fileinfo(db, file, hash_sha256, file_info);
} }
girara_list_t* girara_list_t*

View file

@ -4,6 +4,8 @@
#define DATABASE_H #define DATABASE_H
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <girara/types.h> #include <girara/types.h>
#include <glib-object.h> #include <glib-object.h>
@ -48,9 +50,9 @@ struct _ZathuraDatabaseInterface
bool (*save_jumplist)(ZathuraDatabase* db, const char* file, girara_list_t* jumplist); bool (*save_jumplist)(ZathuraDatabase* db, const char* file, girara_list_t* jumplist);
bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info); bool (*set_fileinfo)(ZathuraDatabase* db, const char* file, const uint8_t* hash_sha256, zathura_fileinfo_t* file_info);
bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, zathura_fileinfo_t* file_info); bool (*get_fileinfo)(ZathuraDatabase* db, const char* file, const uint8_t* hash_sha256, zathura_fileinfo_t* file_info);
girara_list_t* (*get_recent_files)(ZathuraDatabase* db, int max, const char* basepath); girara_list_t* (*get_recent_files)(ZathuraDatabase* db, int max, const char* basepath);
}; };
@ -115,20 +117,23 @@ bool zathura_db_save_jumplist(ZathuraDatabase* db, const char* file, girara_list
* *
* @param db The database instance * @param db The database instance
* @param file The file to which the file info belongs. * @param file The file to which the file info belongs.
* @param hash_sha256 The file's hash
* @param file_info The file info * @param file_info The file info
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, bool zathura_db_set_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
/* Get file info (last site, ...) from the database. /* Get file info (last site, ...) from the database. The info is first looked up by file and then by
* its hash.
* *
* @param db The database instance * @param db The database instance
* @param file The file to which the file info belongs. * @param file The file to which the file info belongs.
* @param hash_sha256 The file's hash
* @param file_info The file info * @param file_info The file info
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, bool zathura_db_get_fileinfo(zathura_database_t* db, const char* file, const uint8_t* hash_sha256,
zathura_fileinfo_t* file_info); zathura_fileinfo_t* file_info);
/* Get a list of recent files from the database. The most recent file is listed /* Get a list of recent files from the database. The most recent file is listed

View file

@ -1006,7 +1006,8 @@ document_open(zathura_t* zathura, const char* path, const char* uri, const char*
}; };
bool known_file = false; bool known_file = false;
if (zathura->database != NULL) { if (zathura->database != NULL) {
known_file = zathura_db_get_fileinfo(zathura->database, file_path, &file_info); const uint8_t* file_hash = zathura_document_get_hash(document);
known_file = zathura_db_get_fileinfo(zathura->database, file_path, file_hash, &file_info);
} }
/* set page offset */ /* set page offset */
@ -1360,6 +1361,7 @@ static void
save_fileinfo_to_db(zathura_t* zathura) save_fileinfo_to_db(zathura_t* zathura)
{ {
const char* path = zathura_document_get_path(zathura->document); const char* path = zathura_document_get_path(zathura->document);
const uint8_t* file_hash = zathura_document_get_hash(zathura->document);
zathura_fileinfo_t file_info = { zathura_fileinfo_t file_info = {
.current_page = zathura_document_get_current_page_number(zathura->document), .current_page = zathura_document_get_current_page_number(zathura->document),
@ -1381,7 +1383,7 @@ save_fileinfo_to_db(zathura_t* zathura)
&(file_info.page_right_to_left)); &(file_info.page_right_to_left));
/* save file info */ /* save file info */
zathura_db_set_fileinfo(zathura->database, path, &file_info); zathura_db_set_fileinfo(zathura->database, path, file_hash, &file_info);
/* save jumplist */ /* save jumplist */
zathura_db_save_jumplist(zathura->database, path, zathura->jumplist.list); zathura_db_save_jumplist(zathura->database, path, zathura->jumplist.list);