mojira.dev
MC-34205

Follow symlinks when saving servers.dat

I have different game directories for different versions of minecraft. To not having to add all servers again with each profile, I symlink a main servers.dat to the specific profile dirs. So far everything works fine. The game follows the symlink and reads the main servers.dat.

But when I add a new server and it tries to save the servers.dat, it doesn't respect the symlink and just overwrites it with a normal file. Instead of following the symlink and overwriting the shared servers.dat.

Linked issues

Comments 13

Try using a hard link instead.

Guybrush Threepwood

Joker.

This ticket is neither invalid nor resolved.

This could be fixed by a simple fix in the code.

And please elaborate to me how i shall hardlink a file on a different filesystem?

If this is across different filesystems then I have no alternative suggestion. This report is invalid as you are not reporting a bug in Minecraft's current functionality, but are rather requesting a change to it. For feature suggestions or changes please do this on Minecraft Suggestions on Reddit.

Seems like a bug to me. Minecraft respects the symlink when reading servers.dat, but ignores the symlink when writing. That behavior is inconsistent.

By your 'current functionality' logic, you could argue than fixing any existing bug is a change to Minecraft's current functionality, and therefore is a feature request.

Minecraft's treatment of symlinks in this situation is inconsistent and unexpected behavior. I can't imagine why this inconsistency would be considered a feature of the current version.

Bug: Minecraft follows symlink when reading, but ignores symlink when writing.

Guybrush Threepwood

Thanks John. I couldn't have stated it better 🙂

But apparently the mods here rather close bug tickets then get them fixed. I saw that a few times already. If this is what you understand under a bugtracker, then you can also just close it down completely and redirect everyone to r/minecraftsuggestions for the 'suggestions'.

3 more comments

Reopening, this is a valid issue. The game is overwriting files rather than editing them, causing the symlinks to be destroyed.

Bug is still present with Minecraft 14w19a and Launcher 1.4.2. Please update affected versions (or tell me how to do it myself). Thanks!

Unpossible to fix, java(6) has no concept of symlinks or not.

Guybrush Threepwood

Shouldn't this work on it's own anyway? Maybe the problem is how you save it. Are you moving/copying a temporary copy of the file on top of the file to write to it? Just guessing here, could also just be a weird java problem.

I believe it's common programming practice when editing files on disk to instead write the whole file out to a new file, then rename it over the old one, unless the file has a fixed-length record structure, or is being managed through a database or filesystem-like framework. This is significantly simpler to do, because it makes editing a file into the same process as writing it from scratch, and you conveniently avoid all the gotchas of tracking changes and random access writing. It also makes the process more resistant to data loss, because if the writing process fails at any point before the rename, you still have the old file as a backup. And the rename should be an atomic operation at the OS level that either fails completely with no damage, or succeeds completely.

Unfortunately, this will break symlinks, because a rename operation (like mv) will operate on the symlink itself, rather than its target. Preserving symlinks requires either doing things the hard, naive way (or getting a library to do it for you), or being able to detect symlinks and deliberately follow them to find the target. Java 6 doesn't have this capability, but Java 7 does, so fixing this would require bumping up the minimum required java version, using an external library of some sort, or writing OS-specific calls. Though supposedly there's a way to check for symlinks by comparing the canonical path to the absolute path.

Guybrush Threepwood

Erik Broes

Unconfirmed

symlink

Minecraft 1.6.4, Minecraft 1.7.1, Minecraft 1.7.2, Minecraft 13w47e, Minecraft 13w48a, ..., Minecraft 14w18b, Minecraft 14w19a, Minecraft 14w20b, Minecraft 14w21a, Minecraft 14w21b

Retrieved