# updated data from files
raise PermissionError("Altering elements in read-only files is "
"disallowed")
+ # Coerce some values to appropriate data types
+ # TODO(fungi) Move these to a separate validation mechanism
if facet in ["loglevel"]:
value = int(value)
elif facet in ["administrator"]:
value = bool(value)
- if not self.has_facet(facet) or not self.get(facet) == value:
- node = ".".join((self.key, facet))
+
+ # The canonical node for this facet within its origin
+ node = ".".join((self.key, facet))
+
+ if node not in self.origin.data or self.origin.data[node] != value:
+ # Be careful to only update the origin's contents when required,
+ # since that affects whether the backing file gets written
self.origin.data[node] = value
- self.facethash[facet] = self.origin.data[node]
self.origin.modified = True
+ # Make sure this facet is included in the element's facets
+ self.facethash[facet] = self.origin.data[node]
+
def append(self, facet, value):
"""Append value to a list."""
newlist = self.get(facet)