diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-06-24 11:50:16 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-06-24 14:25:21 -0500 |
| commit | 054fda56ef8da2bb2b0c1f9749914189d13e3d07 (patch) | |
| tree | 92a8781f4c1919837c35e3d1e3c1bfd705e52cf6 /python | |
| parent | d3826867554eb9dbd30d5c8c781516a8afcfd96b (diff) | |
| download | vyos-1x-054fda56ef8da2bb2b0c1f9749914189d13e3d07.tar.gz vyos-1x-054fda56ef8da2bb2b0c1f9749914189d13e3d07.zip | |
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.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/configtree.py | 14 |
1 files changed, 11 insertions, 3 deletions
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()) |
