[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/maint-1.1] fix: state: Read file before setting key



commit fe827ac182d7cee0061660d32dd56a7d11af3c65
Author: juga0 <juga@xxxxxxxxxx>
Date:   Sat Mar 14 17:10:57 2020 +0000

    fix: state: Read file before setting key
    
    Otherwise, if other instance of state set a key, it's lost by the
    current instance.
    
    Bugfix v0.7.0.
---
 sbws/util/state.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sbws/util/state.py b/sbws/util/state.py
index 1d33c3d..f460413 100644
--- a/sbws/util/state.py
+++ b/sbws/util/state.py
@@ -97,6 +97,9 @@ class State:
             raise TypeError(
                 'May only store value with type in %s, not %s' %
                 (State._ALLOWED_TYPES, type(value)))
+        # NOTE: important, read the file before setting the key,
+        # otherwise if other instances are creating other keys, they're lost.
+        self._state = self._read()
         self._state.__setitem__(key, value)
         self._write()
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits