Fix handling of config file deleted at runtime

This commit is contained in:
miruka 2020-11-15 20:11:30 -04:00
parent c1dc9a80b2
commit a53aec0ff9

View File

@ -115,9 +115,9 @@ class UserFile:
ignored = 0 ignored = 0
for change in changes: for change in changes:
if change[0] in (Change.added, Change.modified):
mtime = self.path.stat().st_mtime mtime = self.path.stat().st_mtime
if change[0] in (Change.added, Change.modified):
if mtime == self._mtime: if mtime == self._mtime:
ignored += 1 ignored += 1
continue continue
@ -129,15 +129,20 @@ class UserFile:
if save: if save:
self.save() self.save()
self._mtime = mtime
elif change[0] == Change.deleted: elif change[0] == Change.deleted:
self._mtime = None
self.data = self.default_data self.data = self.default_data
self._need_write = self.create_missing self._need_write = self.create_missing
self._mtime = mtime
if changes and ignored < len(changes): if changes and ignored < len(changes):
UserFileChanged(type(self), self.qml_data) UserFileChanged(type(self), self.qml_data)
while not self.path.exists():
# Prevent error spam after file gets deleted
await asyncio.sleep(0.5)
except Exception as err: # noqa except Exception as err: # noqa
LoopException(str(err), err, traceback.format_exc().rstrip()) LoopException(str(err), err, traceback.format_exc().rstrip())