From 054fda56ef8da2bb2b0c1f9749914189d13e3d07 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 24 Jun 2026 11:50:16 -0500 Subject: T9015: use file operations on Python side for read/write_cache to file For thread-safe calls, move file operations to the Python side, leaving only string operations for calls to ctypes bindings. --- python/vyos/configtree.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 24b3252fd..a70aac095 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -72,7 +72,7 @@ class ConfigTreeError(Exception): class ConfigTree: - # pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-statements,too-many-public-methods + # pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-statements,too-many-public-methods,raise-missing-from def __init__( self, config_string=None, @@ -232,7 +232,11 @@ class ConfigTree: self.__config = address self.__version = '' case ('internal', internal): - config = self.__read_internal(internal.encode()) + try: + cache_string = Path(internal).read_bytes() + except OSError as e: + raise ValueError(f'Failed to read internal cache file: {e}') + config = self.__read_internal_string(cache_string) if config is None: msg = self.__get_error().decode() raise ValueError( @@ -299,7 +303,11 @@ class ConfigTree: return self.__version def write_cache(self, file_name): - self.__write_internal(self.get_tree(), file_name.encode()) + cache_string = self.__write_internal_string(self.get_tree()) + try: + Path(file_name).write_bytes(cache_string) + except OSError as e: + raise ValueError(f'Failed to write internal cache file: {e}') def write_internal_string(self) -> str: res = self.__write_internal_string(self.get_tree()) -- cgit v1.2.3