Skip to content

Commit

Permalink
Ignore race conditions loading config
Browse files Browse the repository at this point in the history
by jelmer review by jelmer
jelmer authored and The Breezy Bot committed Mar 24, 2024
2 parents c51bcd8 + d2e4b54 commit 972953f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions breezy/config.py
Original file line number Diff line number Diff line change
@@ -3169,18 +3169,22 @@ def _load_from_string(self, bytes):
Args:
bytes: A string representing the file content.
"""
if self.is_loaded():
raise AssertionError(f"Already loaded: {self._config_obj!r}")
co_input = BytesIO(bytes)
try:
# The config files are always stored utf8-encoded
self._config_obj = ConfigObj(co_input, encoding="utf-8", list_values=False)
new_config_obj = ConfigObj(co_input, encoding="utf-8", list_values=False)
except configobj.ConfigObjError as e:
self._config_obj = None
raise ParseConfigError(e.errors, self.external_url()) from e
except UnicodeDecodeError as e:
raise ConfigContentError(self.external_url()) from e

if self._config_obj is not None:
if new_config_obj != self._config_obj:
raise AssertionError("ConfigObj instances are not equal")

self._config_obj = new_config_obj

def save_changes(self):
if not self.is_loaded():
# Nothing to save

0 comments on commit 972953f

Please sign in to comment.