From d2c52e26731e25b09e2c5bedc3df602a3a23be5a Mon Sep 17 00:00:00 2001 From: Sniffleupagus Date: Fri, 19 May 2023 11:01:08 -0700 Subject: [PATCH] save backups of brain files when saving --- pwnagotchi/ai/train.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pwnagotchi/ai/train.py b/pwnagotchi/ai/train.py index c9846ca6..2d72e6e6 100644 --- a/pwnagotchi/ai/train.py +++ b/pwnagotchi/ai/train.py @@ -81,7 +81,8 @@ class Stats(object): with open(temp, 'wt') as fp: fp.write(data) - os.replace(self.path, back) + if os.path.isfile(self.path): + os.replace(self.path, back) os.replace(temp, self.path) @@ -117,7 +118,8 @@ class AsyncTrainer(object): temp = "%s.tmp" % self._nn_path back = "%s.bak" % self._nn_path self._model.save(temp) - os.replace(self._nn_path, back) + if os.path.isfile(self._nn_path): + os.replace(self._nn_path, back) os.replace(temp, self._nn_path) def on_ai_step(self):