-
-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add safe config updating #7224
base: dev/feature
Are you sure you want to change the base?
Add safe config updating #7224
Conversation
|
||
File backup = FileUtils.backup(configFile); | ||
boolean updated = mainConfig.updateNodes(newConfig); | ||
// mainConfig.getMainNode().set(version.key, Skript.getVersion().toString()); TODO FOR TESTING! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just so i dont forget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far. Here's what I found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want the node classes to be reformatted in this PR.
Description
Changes
Config#updateNodes
About updateNodes
Config#updateNodes
differs from the current behaviour ofConfig#setValues
as it does not touch any nodes in the existing config ("the old config") that are also present in the config provided with Skript ("the new config"). This ensures safety for critical sections like thedatabases
section.First, the difference between the nodes of the new and old config is found. These nodes that are missing from the old config will then be added to the old config at the index (the amount of nodes prior to the current one) at which they were found in the new config.
Testing
From my testing, this only seems to break when the old config is made invalid by de-indenting one of the entry nodes. This means the path of the following nodes are all different until the start of the next section (at the same indentation as the currently de-indented entry node, not any children). As a node's path is used to determine whether it is missing from the config, this will cause these following nodes to de-indent as well, deleting the current section head. This seems to be fixed by adding a check for whether the parsed config is valid, by using
SectionNode#isValid
.Limitations
Currently, outdated comments are not deleted and I'm not sure whether we want to support keeping user-added comments present. Should this be added?
Removed
My sanity
Target Minecraft Versions: any
Requirements: none
Related Issues: #7184