From 1a76f2ecb9326eff72d99b9f1a14cf2bb9aeb8d6 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 20 Jan 2007 12:33:47 +1000 Subject: [PATCH] Do not purge internal history if saving history to file fails darcs-hash:20070120023347-ac50b-8e61c5f65cfca3ffdb6dd740fc32b91a975fdb87.gz --- history.c | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/history.c b/history.c index 9bb520c3a..c607092c1 100644 --- a/history.c +++ b/history.c @@ -1,5 +1,5 @@ /** \file history.c - History functions, part of the user interface. + History functions, part of the user interface. */ #include "config.h" @@ -612,6 +612,8 @@ static void history_save_mode( void *n, history_mode_t *m ) int has_new=0; wchar_t *tmp_name; + int ok = 1; + /* First check if there are any new entries to save. If not, then we can just return @@ -649,7 +651,6 @@ static void history_save_mode( void *n, history_mode_t *m ) if( (out=wfopen( tmp_name, "w" ) ) ) { hash_table_t mine; - int ok = 1; hash_init( &mine, &hash_item_func, &hash_item_cmp ); @@ -717,26 +718,32 @@ static void history_save_mode( void *n, history_mode_t *m ) halloc_free( on_disk); - /* - Reset the history. The item_t entries created in this session - are not lost or dropped, they are stored in the session_item - hash table. On reload, they will be automatically inserted at - the end of the history list. - */ - - if( m->mmap_start && (m->mmap_start != MAP_FAILED ) ) - munmap( m->mmap_start, m->mmap_length ); - - al_truncate( &m->item, 0 ); - al_truncate( &m->used, 0 ); - m->pos = 0; - m->has_loaded = 0; - m->mmap_start=0; - m->mmap_length=0; - - m->save_timestamp=time(0); - m->new_count = 0; + if( ok ) + { + /* + Reset the history. The item_t entries created in this session + are not lost or dropped, they are stored in the session_item + hash table. On reload, they will be automatically inserted at + the end of the history list. + */ + + if( m->mmap_start && (m->mmap_start != MAP_FAILED ) ) + { + munmap( m->mmap_start, m->mmap_length ); + } + + al_truncate( &m->item, 0 ); + al_truncate( &m->used, 0 ); + m->pos = 0; + m->has_loaded = 0; + m->mmap_start=0; + m->mmap_length=0; + + m->save_timestamp=time(0); + m->new_count = 0; + } + signal_unblock(); }