From bff8948116283b28de29afc6d14539a5f1794451 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 9 Sep 2020 22:46:18 +0200 Subject: [PATCH] [DRun] Fix broken cache after URL type was added. --- source/dialogs/drun.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index cb7bd2c2..aac7a934 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -723,7 +723,7 @@ static gint drun_int_sort_list ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED * Cache voodoo * *******************************************/ -#define CACHE_VERSION 1 +#define CACHE_VERSION 2 static void drun_write_str ( FILE *fd, const char *str ) { size_t l = ( str == NULL ? 0 : strlen ( str ) ); @@ -734,6 +734,17 @@ static void drun_write_str ( FILE *fd, const char *str ) fwrite ( str, 1, l + 1, fd ); } } +static void drun_write_integer ( FILE *fd, int32_t val ) +{ + fwrite ( &val,sizeof(val), 1, fd ); +} +static void drun_read_integer ( FILE *fd, int32_t *type ) +{ + if ( fread ( type, sizeof ( int32_t), 1, fd ) != 1 ) { + g_warning ( "Failed to read entry, cache corrupt?" ); + return; + } +} static void drun_read_string ( FILE *fd, char **str ) { size_t l = 0; @@ -810,6 +821,7 @@ static void write_cache ( DRunModePrivateData *pd, const char *cache_file ) drun_write_strv ( fd, entry->keywords ); drun_write_str ( fd, entry->comment ); + drun_write_integer ( fd, (int32_t)entry->type ); } fclose ( fd ); @@ -842,21 +854,21 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil fclose ( fd ); g_warning ( "Cache corrupt, ignoring." ); TICK_N ( "DRUN Read CACHE: stop" ); - return FALSE; + return TRUE; } if ( version != CACHE_VERSION ) { fclose ( fd ); g_warning ( "Cache file wrong version, ignoring." ); TICK_N ( "DRUN Read CACHE: stop" ); - return FALSE; + return TRUE; } if ( fread ( &( pd->cmd_list_length ), sizeof ( pd->cmd_list_length ), 1, fd ) != 1 ) { fclose ( fd ); g_warning ( "Cache corrupt, ignoring." ); TICK_N ( "DRUN Read CACHE: stop" ); - return FALSE; + return TRUE; } // set actual length to length; pd->cmd_list_length_actual = pd->cmd_list_length; @@ -880,6 +892,9 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil drun_read_stringv ( fd, &( entry->keywords ) ); drun_read_string ( fd, &( entry->comment ) ); + int32_t type = 0; + drun_read_integer( fd, &( type ) ); + entry->type = type; } fclose ( fd );