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
  • Loading branch information
jelmer authored and The Breezy Bot committed Mar 24, 2024
2 parents d8856fe + d483887 commit 8375a1a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions breezy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2991,19 +2991,22 @@ def _load_from_string(self, bytes):
Args:
bytes: A string representing the file content.
"""
if self.is_loaded():
raise AssertionError('Already loaded: {!r}'.format(self._config_obj))
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())
except UnicodeDecodeError:
raise ConfigContentError(self.external_url())

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
Expand Down

0 comments on commit 8375a1a

Please sign in to comment.