Skip to content
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

Open
wants to merge 29 commits into
base: dev/feature
Choose a base branch
from
Open

Conversation

Efnilite
Copy link
Member

Description

Changes

  • Fixes New 'backups to keep' entry not generated for existing configs #7184
  • Reformats all classes to be more up to date with code standards
    • Any non-new method changes are for improving code readability, improving the position of the methods in the class or using pattern matching.
  • Deprecates the current method for config updating, replacing it with Config#updateNodes

About updateNodes
Config#updateNodes differs from the current behaviour of Config#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 the databases 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

@Efnilite Efnilite added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: high Issues with potentially high impact that could be harmful to users. needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls. 2.10 Targeting a 2.10.X version release labels Nov 21, 2024

File backup = FileUtils.backup(configFile);
boolean updated = mainConfig.updateNodes(newConfig);
// mainConfig.getMainNode().set(version.key, Skript.getVersion().toString()); TODO FOR TESTING!
Copy link
Member Author

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

@Efnilite Efnilite removed the priority: high Issues with potentially high impact that could be harmful to users. label Nov 22, 2024
Copy link
Member

@APickledWalrus APickledWalrus left a 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.

src/main/java/ch/njol/skript/config/SimpleNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Node.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/EntryNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/SectionNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/SectionNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/SectionNode.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Config.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/config/Config.java Outdated Show resolved Hide resolved
@Efnilite Efnilite requested a review from Moderocky November 23, 2024 09:14
Copy link
Member

@Moderocky Moderocky left a 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.

@Efnilite Efnilite changed the title Add safe config updating, update config classes Add safe config updating Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 Targeting a 2.10.X version release bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants