Drop the XML backup file
This commit is contained in:
@@ -64,12 +64,11 @@ class XMLReadState(Enum):
|
||||
|
||||
NO_ACTION = 0
|
||||
NO_ERROR = 1
|
||||
PARSED_BACKUP = 2
|
||||
CANNOT_PARSE = 3
|
||||
NOT_NWX_FILE = 4
|
||||
UNKNOWN_VERSION = 5
|
||||
PARSED_OK = 6
|
||||
WAS_LEGACY = 7
|
||||
CANNOT_PARSE = 2
|
||||
NOT_NWX_FILE = 3
|
||||
UNKNOWN_VERSION = 4
|
||||
PARSED_OK = 5
|
||||
WAS_LEGACY = 6
|
||||
|
||||
# END Class XMLReadState
|
||||
|
||||
@@ -171,23 +170,9 @@ class ProjectXMLReader:
|
||||
xml = ET.parse(str(self._path))
|
||||
self._state = XMLReadState.NO_ERROR
|
||||
except Exception as exc:
|
||||
# Trying to open backup file instead
|
||||
logger.error("Failed to parse project XML", exc_info=exc)
|
||||
self._state = XMLReadState.CANNOT_PARSE
|
||||
|
||||
backFile = self._path.with_suffix(".bak")
|
||||
if backFile.is_file():
|
||||
try:
|
||||
xml = ET.parse(str(backFile))
|
||||
self._state = XMLReadState.PARSED_BACKUP
|
||||
logger.info("Backup project file parsed")
|
||||
except Exception as exc:
|
||||
logger.error("Failed to parse backup project XML", exc_info=exc)
|
||||
self._state = XMLReadState.CANNOT_PARSE
|
||||
return False
|
||||
else:
|
||||
self._state = XMLReadState.CANNOT_PARSE
|
||||
return False
|
||||
return False
|
||||
|
||||
xRoot = xml.getroot()
|
||||
self._root = str(xRoot.tag)
|
||||
@@ -557,22 +542,12 @@ class ProjectXMLWriter:
|
||||
xName.text = item["name"]
|
||||
|
||||
# Write the XML tree to file
|
||||
tempFile = self._path.with_suffix(".tmp")
|
||||
backFile = self._path.with_suffix(".bak")
|
||||
tmp = self._path.with_suffix(".tmp")
|
||||
try:
|
||||
xml = ET.ElementTree(xRoot)
|
||||
xmlIndent(xml)
|
||||
xml.write(tempFile, encoding="utf-8", xml_declaration=True)
|
||||
except Exception as exc:
|
||||
self._error = exc
|
||||
return False
|
||||
|
||||
# If we're here, the file was successfully saved,
|
||||
# so let's sort out the temps and backups
|
||||
try:
|
||||
if self._path.exists():
|
||||
self._path.replace(backFile)
|
||||
tempFile.replace(self._path)
|
||||
xml.write(tmp, encoding="utf-8", xml_declaration=True)
|
||||
tmp.replace(self._path)
|
||||
except Exception as exc:
|
||||
self._error = exc
|
||||
return False
|
||||
|
||||
@@ -307,7 +307,6 @@ class NWStorage:
|
||||
baseCont = basePath / "content"
|
||||
files = [
|
||||
(basePath / nwFiles.PROJ_FILE, nwFiles.PROJ_FILE),
|
||||
(basePath / nwFiles.PROJ_BACKUP, nwFiles.PROJ_BACKUP),
|
||||
(baseMeta / nwFiles.BUILDS_FILE, f"meta/{nwFiles.BUILDS_FILE}"),
|
||||
(baseMeta / nwFiles.INDEX_FILE, f"meta/{nwFiles.INDEX_FILE}"),
|
||||
(baseMeta / nwFiles.OPTS_FILE, f"meta/{nwFiles.OPTS_FILE}"),
|
||||
@@ -463,6 +462,7 @@ class _LegacyStorage:
|
||||
path / "cache" / "prevBuild.json", # Dropped in 2.1 Beta 1
|
||||
path / "cache", # Dropped in 2.1 Beta 1
|
||||
path / "ToC.json", # Dropped in 1.0 RC 1
|
||||
path / "nwProject.bak", # Dropped in 2.3 Beta 1
|
||||
]
|
||||
for item in remove:
|
||||
if item.exists():
|
||||
|
||||
Reference in New Issue
Block a user