diff options
| author | Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> | 2026-02-25 13:27:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-25 13:27:19 +0200 |
| commit | 6fd7a87116ea91edbdbe86ed19c8274682d9ee8b (patch) | |
| tree | b59cdd8262d1546589a952e6d9544231d72ba34d /python | |
| parent | 7fcca39afcafc9d99a58abc898460c975a5cdd34 (diff) | |
| parent | e8c6a8f37470416e72a26fbbdfad24f8dcea7208 (diff) | |
| download | vyos-1x-6fd7a87116ea91edbdbe86ed19c8274682d9ee8b.tar.gz vyos-1x-6fd7a87116ea91edbdbe86ed19c8274682d9ee8b.zip | |
Merge pull request #5008 from alexandr-san4ez/T8297-current
vpp: T8297: Fixed double enabling of VPP
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/vpp/configdb.py | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/python/vyos/vpp/configdb.py b/python/vyos/vpp/configdb.py index 13c1cd3a0..e86b32fb7 100644 --- a/python/vyos/vpp/configdb.py +++ b/python/vyos/vpp/configdb.py @@ -34,6 +34,10 @@ class JSONStorage: """ # If a name is not provided, this is a temporary one-time storage # this use case is strange, but let's allow this + + # Indicates that the object has already been closed and cannot be used again + self.__closed = False + if not name: self.__temporary = True self.__cache: dict[Any, Any] = {} @@ -68,17 +72,34 @@ class JSONStorage: self.__cache = self.__load_file() def __del__(self) -> None: + self.close() + + def __enter__(self): + return self + + def __exit__(self, *exc): + self.close() + + def close(self): """Dump data to persistent storage and unlock it""" - if self.__temporary: + + # Do not do anything if it is already closed storage + if self.__closed: return - # dump a cache to storage - if self.__cache: - self.__dump_file() - # or remove a file - else: - self.__storage.unlink() - # unlock a storage - self.__lock_file.unlink() + + try: + if self.__temporary: + return + # dump a cache to storage + if self.__cache: + self.__dump_file() + # or remove a file + else: + self.__storage.unlink(missing_ok=True) + # unlock a storage + self.__lock_file.unlink(missing_ok=True) + finally: + self.__closed = True def __check_types(self, data: Any) -> None: """Check if all the data have supported types |
