From fbe1766aea151e5e7c642aeeac039455c4c7dd6a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 20 Sep 2019 09:47:14 -0500 Subject: [PATCH] fix filenotfound error in softreset, added softreset event --- onionr/onionrcommands/softreset.py | 13 +++++++++++-- onionr/static-data/default-plugins/flow/main.py | 13 ++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/onionr/onionrcommands/softreset.py b/onionr/onionrcommands/softreset.py index 68f5f96e..2ef12e4e 100644 --- a/onionr/onionrcommands/softreset.py +++ b/onionr/onionrcommands/softreset.py @@ -23,15 +23,24 @@ import shutil from onionrutils import localcommand from coredb import dbfiles import filepaths +import onionrevents import logger + +def _ignore_not_found_delete(path): + try: + os.remove(path) + except FileNotFoundError: + pass + def soft_reset(): if localcommand.local_command('/ping') == 'pong!': logger.warn('Cannot soft reset while Onionr is running', terminal=True) return path = filepaths.block_data_location shutil.rmtree(path) - os.remove(dbfiles.block_meta_db) - os.remove(filepaths.upload_list) + _ignore_not_found_delete(dbfiles.block_meta_db) + _ignore_not_found_delete(filepaths.upload_list) + onionrevents.event('softreset') logger.info("Soft reset Onionr", terminal=True) soft_reset.onionr_help = "Deletes Onionr blocks and their associated metadata, except for any exported block files." \ No newline at end of file diff --git a/onionr/static-data/default-plugins/flow/main.py b/onionr/static-data/default-plugins/flow/main.py index b0263f8c..6029ce8a 100755 --- a/onionr/static-data/default-plugins/flow/main.py +++ b/onionr/static-data/default-plugins/flow/main.py @@ -99,13 +99,12 @@ class OnionrFlow: def on_flow_cmd(api, data=None): OnionrFlow().start() -def on_init(api, data = None): - ''' - This event is called after Onionr is initialized, but before the command - inputted is executed. Could be called when daemon is starting or when - just the client is running. - ''' - return +def on_softreset(api, data=None): + try: + os.remove(identifyhome.identify_home() + '/board-index.cache.json') + logger.info('Cleared Circles board cache') + except FileNotFoundError: + pass def on_processblocks(api, data=None): metadata = data['block'].bmetadata # Get the block metadata