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

juga at torproject.org juga at torproject.org
Tue Apr 14 13:53:19 UTC 2020


commit fe827ac182d7cee0061660d32dd56a7d11af3c65
Author: juga0 <juga at riseup.net>
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()
 





More information about the tor-commits mailing list