-
Notifications
You must be signed in to change notification settings - Fork 21
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
Backup save related files outside of save folder #178
base: master
Are you sure you want to change the base?
Conversation
Have you tested how restoring a backup from the in-game menu interacts with this? |
I feel like this feature could help enable seamless in-place pack updates. |
I pushed a rework, addressing the mentioned issues. I still need to test it more before I consider it ready, though. |
Windows doesn't seem to like those wildcards
|
"saves/NEI/global/**", "saves/NEI/local/$WORLDNAME/**", "visualprospecting/client/*/$WORLDNAME_*/**", | ||
"visualprospecting/server/$WORLDNAME_*/**", "visualprospecting/veintypesLUT", "schematics/**", | ||
"blueprints/**" }) | ||
public String[] additional_backup_files; |
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.
These are fine as GTNH defaults, but I don't see why most of these need to be mod defaults.
(also veintypesLUT is gone after 2.7.x)
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.
Which ones would you leave in? Just NEI, or nothing?
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.
The NEI/local/
subfolder is fine to keep imo, but restoring the NEI/global/
folder can cause some unintended consequences if the player restores a backup from an old world.
The trailing **
aren't necessary since FileUtils.listFiles()
will include the entire subdirectory anyways.
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.
The trailing **
are needed for the PathMatcher to work.
Regarding NEI/global
: But on the other hand it would make sense to backup and restore in case it got corrupted. Not sure how I should handle this?
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.
Regarding
NEI/global
: But on the other hand it would make sense to backup and restore in case it got corrupted. Not sure how I should handle this?
We can't safely restore data that isn't related to the world.
for (String pattern : backups.additional_backup_files) { | ||
pattern = pattern.replace("$WORLDNAME", worldName); | ||
|
||
String rootFolder = String.valueOf(Paths.get(pattern).getName(0)); | ||
|
||
File original = new File(rootFolder); | ||
if (original.isDirectory()) { | ||
File copy = new File(rootFolder + "_old"); | ||
while (copy.exists()) { | ||
copy = new File(copy.getName() + "_old"); | ||
} | ||
original.renameTo(copy); // Rename original and don't change that again | ||
|
||
try { | ||
org.apache.commons.io.FileUtils.copyDirectory(copy, original); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// Delete all matching files from directory, so we can cleanly restore the backup | ||
List<File> fileCandidates = FileUtils.listTree(original); | ||
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); | ||
|
||
for (File file : fileCandidates) { | ||
if (matcher.matches(file.toPath())) { | ||
file.delete(); | ||
} |
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 think it's a good idea to leave _old versions of all the files stored outside of the saves folder, it's only done with the world folder because the copy is directly visual in the world select menu. This risks creating potentially big copies in folders that players very rarely have any reason to look in.
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.
Is there a good alternative? Deleting all old data without a backup sounds dangerous.
Edit: I also found another issue where it created more than one _old folder, but I didn't fix that yet since it might get removed
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.
Idk what the alternative could be, maybe someone else can weigh in on that.
Personally I think it's a very bad idea to duplicate all this data in various folders every time a backup is restored.
This includes by default: - journeymap data - NEI data - TCNodeTracker data - visualprospecting data - schematics - blueprints
Seems like Windows java doesn't like "*" in the paths, I pushed an update that should fix that. Although I can't fully test since I currently can't test on Windows. |
Stripping the path of all Also all those force pushes makes it very hard to track what was actually changed. |
I only remove the
Sorry, I'm used to gitlab where that is no problem, I will make additional commits from now on. |
If you're only using the PathMatcher to resolve the wildcards it would be much more efficient to only resolve the part of the path that contains a wildcard, instead of trying to match every file in the root folder against the pattern. Doing it this way means that it'll iterate through potentially thousands of files, since all content of the subfolders is included, to only add a few of those files to the backup. |
Thanks for your in-depth review, appreciate it! I pushed a fix that only iterates as many files as needed. Could you please open conversations for future issue? I find it to be easier to follow, since it groups. |
This includes:
Fixes #120
Note that I don't know what exactly is stored inside blueprints, I never used it