X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=157096c0cb8ba2fa491b6686f92142b5c18dcc89;hp=af5427a86a059c091c6a41e899d0790a960f887f;hb=7a0a96095780b29d58a9d5aa8ece1fabaab72a2c;hpb=11ae0d6e7e05cffb744f7b40f37309f07696d34a diff --git a/mudpy/misc.py b/mudpy/misc.py index af5427a..157096c 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -154,6 +154,12 @@ class Element: 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: @@ -347,6 +353,7 @@ class Universe: self.contents = {} self.default_origins = {} self.directions = set() + self.loading = False self.loglines = [] self.private_files = [] self.reload_flag = False @@ -375,6 +382,9 @@ class Universe: def load(self): """Load universe data from persistent storage.""" + # while loading, it's safe to update elements from read-only files + self.loading = True + # it's possible for this to enter before logging configuration is read pending_loglines = [] @@ -425,6 +435,10 @@ class Universe: for element in self.contents.values(): element.update_location() element.clean_contents() + + # done loading, so disallow updating elements from read-only files + self.loading = False + return pending_loglines def new(self):