[tor-commits] [sbws/master] Check if file exists before locking it

juga at torproject.org juga at torproject.org
Tue Sep 18 09:26:11 UTC 2018


commit 850271a127956213d432e93e9e0fdab0689a1cf6
Author: juga0 <juga at riseup.net>
Date:   Wed Aug 29 18:50:48 2018 +0000

    Check if file exists before locking it
---
 sbws/util/state.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbws/util/state.py b/sbws/util/state.py
index a13ee13..ce3dbb9 100644
--- a/sbws/util/state.py
+++ b/sbws/util/state.py
@@ -48,9 +48,9 @@ class State:
         self._state = self._read()
 
     def _read(self):
+        if not os.path.exists(self._fname):
+            return {}
         with FileLock(self._fname):
-            if not os.path.exists(self._fname):
-                return {}
             with open(self._fname, 'rt') as fd:
                 return json.load(fd)
 





More information about the tor-commits mailing list