Refuse to alter read-only elements at runtime
authorJeremy Stanley <fungi@yuggoth.org>
Mon, 31 Jul 2017 15:00:33 +0000 (15:00 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Mon, 31 Jul 2017 15:00:33 +0000 (15:00 +0000)
In the Element.set() method, check whether the element being altered
is from a read-only file. That should only ever happen when
(re)loading of files is underway, either at start time or because
the reload command/SIGHUP has been issued. If an attempt is made to
change a read-only element at any other time, raise a
PermissionError exception instead of setting the new value in memory
(altered values were never written to the backing file, but prior to
this it was possible to modify the in-memory copies).

mudpy/misc.py

index 4e32ccc..157096c 100644 (file)
@@ -154,6 +154,12 @@ class Element:
 
     def set(self, facet, value):
         """Set values."""
 
     def set(self, facet, value):
         """Set values."""
+        if not self.origin.is_writeable() and not self.universe.loading:
+            # break if there is an attempt to update an element from a
+            # read-only file, unless the universe is in the midst of loading
+            # updated data from files
+            raise PermissionError("Altering elements in read-only files is "
+                                  "disallowed")
         if facet in ["loglevel"]:
             value = int(value)
         if not self.has_facet(facet) or not self.get(facet) == value:
         if facet in ["loglevel"]:
             value = int(value)
         if not self.has_facet(facet) or not self.get(facet) == value: