aboutsummaryrefslogtreecommitdiffstats
path: root/klippy
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-09-26 00:47:10 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-10-30 14:42:53 -0400
commit85ebafd3f6c4e39f445ac7eac42bebc6587c1a7c (patch)
tree4dfec8fab71f00189f6335afed9fcdb722895ff4 /klippy
parent9adb313ee870fd7bfa6b7dd363d36e609788e531 (diff)
downloadkutter-85ebafd3f6c4e39f445ac7eac42bebc6587c1a7c.tar.gz
kutter-85ebafd3f6c4e39f445ac7eac42bebc6587c1a7c.tar.xz
kutter-85ebafd3f6c4e39f445ac7eac42bebc6587c1a7c.zip
configfile: Don't read the autosave data if multiple autosave headers present
Also, verify new autosave looks valid prior to writing it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy')
-rw-r--r--klippy/configfile.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py
index 5b9896a0..497f35ed 100644
--- a/klippy/configfile.py
+++ b/klippy/configfile.py
@@ -247,7 +247,7 @@ class ConfigAutoSave:
regular_data = data[:pos]
autosave_data = data[pos + len(AUTOSAVE_HEADER):].strip()
# Check for errors and strip line prefixes
- if "\n#*# " in regular_data:
+ if "\n#*# " in regular_data or autosave_data.find(AUTOSAVE_HEADER) >= 0:
logging.warning("Can't read autosave from config file"
" - autosave state corrupted")
return data, ""
@@ -361,6 +361,11 @@ class ConfigAutoSave:
regular_data = self._strip_duplicates(regular_data, self.fileconfig)
self._disallow_include_conflicts(regular_data, cfgname, gcode)
data = regular_data.rstrip() + autosave_data
+ new_regular_data, new_autosave_data = self._find_autosave_data(data)
+ if not new_autosave_data:
+ raise gcode.error(
+ "Existing config autosave is corrupted."
+ " Can't complete SAVE_CONFIG")
# Determine filenames
datestr = time.strftime("-%Y%m%d_%H%M%S")
backup_name = cfgname + datestr