mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Guard against unexpected file structures
We shouldn't break on that. Contributes to issue CURA-7024.
This commit is contained in:
parent
a1f3444271
commit
3513266549
1 changed files with 16 additions and 3 deletions
|
@ -72,7 +72,12 @@ class VersionUpgrade44to45(VersionUpgrade):
|
|||
dirs[:] = [dir for dir in dirs if dir not in exclude_directories]
|
||||
for filename in fnmatch.filter(files, "*.global.cfg"):
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
parser.read(os.path.join(root, filename))
|
||||
try:
|
||||
parser.read(os.path.join(root, filename))
|
||||
except OSError: # File not found or insufficient rights.
|
||||
continue
|
||||
except configparser.Error: # Invalid file format.
|
||||
continue
|
||||
if "metadata" in parser and "hidden" in parser["metadata"] and parser["metadata"]["hidden"] == "True":
|
||||
stack_id = urllib.parse.unquote_plus(os.path.basename(filename).split(".")[0])
|
||||
hidden_global_stacks.add(stack_id)
|
||||
|
@ -89,7 +94,12 @@ class VersionUpgrade44to45(VersionUpgrade):
|
|||
dirs[:] = [dir for dir in dirs if dir not in exclude_directories]
|
||||
for filename in fnmatch.filter(files, "*.extruder.cfg"):
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
parser.read(os.path.join(root, filename))
|
||||
try:
|
||||
parser.read(os.path.join(root, filename))
|
||||
except OSError: # File not found or insufficient rights.
|
||||
continue
|
||||
except configparser.Error: # Invalid file format.
|
||||
continue
|
||||
if "metadata" in parser and "machine" in parser["metadata"] and parser["metadata"]["machine"] in hidden_global_stacks:
|
||||
stack_id = urllib.parse.unquote_plus(os.path.basename(filename).split(".")[0])
|
||||
hidden_extruder_stacks.add(stack_id)
|
||||
|
@ -107,7 +117,10 @@ class VersionUpgrade44to45(VersionUpgrade):
|
|||
for filename in fnmatch.filter(files, "*.inst.cfg"):
|
||||
container_id = urllib.parse.unquote_plus(os.path.basename(filename).split(".")[0])
|
||||
if container_id in hidden_instance_containers:
|
||||
os.remove(os.path.join(root, filename))
|
||||
try:
|
||||
os.remove(os.path.join(root, filename))
|
||||
except OSError: # Is a directory, file not found, or insufficient rights.
|
||||
continue
|
||||
|
||||
def getCfgVersion(self, serialised: str) -> int:
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue