https://fedorahosted.org/freeipa/ticket/4901
--
David Kupka
From f7c47015b40141e0d1c5d93add4b7293a95cd830 Mon Sep 17 00:00:00 2001
From: David Kupka <dku...@redhat.com>
Date: Mon, 16 Mar 2015 08:05:59 -0400
Subject: [PATCH] Always reload StateFile before getting or modifying the
 stored values.

This change does not solve using multiple instances of StateFile concurently
because there is no use for it in near future. Instead this solves an issue of loosing
records when more instances of StateFile are interleaved in sequential code.

https://fedorahosted.org/freeipa/ticket/4901
---
 ipapython/sysrestore.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index 6db33a7efe944baca5838264040d71cd06e6129c..580df9a4fd6d0fae35602dad1f81d498fa8f0173 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -283,8 +283,11 @@ class FileStore:
 
 class StateFile:
     """A metadata file for recording system state which can
-    be backed up and later restored. The format is something
-    like:
+    be backed up and later restored.
+    StateFile gets reloaded every time to prevent loss of information
+    recorded by child processes. But we do not solve concurrency
+    because there is no need for it right now.
+    The format is something like:
 
     [httpd]
     running=True
@@ -363,6 +366,8 @@ class StateFile:
         if not isinstance(value, (str, bool, unicode)):
             raise ValueError("Only strings, booleans or unicode strings are supported")
 
+        self._load()
+
         if not self.modules.has_key(module):
             self.modules[module] = {}
 
@@ -378,6 +383,8 @@ class StateFile:
         If the item doesn't exist, #None will be returned, otherwise
         the original string or boolean value is returned.
         """
+        self._load()
+
         if not self.modules.has_key(module):
             return None
 
@@ -389,6 +396,8 @@ class StateFile:
 
         If the item doesn't exist, no change is done.
         """
+        self._load()
+
         try:
             del self.modules[module][key]
         except KeyError:
-- 
2.1.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to