TISUnion / QuickBackupM

A backup / restore plugin, with multiple backup slots
GNU General Public License v3.0
148 stars 20 forks source link

Support handling symbolic link world folder #29

Closed Vigilans closed 2 years ago

Vigilans commented 2 years ago

Currently, when the world folder to backup is a symbolic link, shutil.rmtree in remove_worlds will raise an exception:

# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link")

This PR adds proper support for handling symbolic link by copying/removing related files recursively dereferenced from the symlink to the real folder.

This PR does not change any behavior in current QuickBackupM's implementation, since the entrypoint to added code is scoped only to symlink files by while os.path.islink(src_path).

Use case

Suppose server folder contains multiple redstone saves downloaded from internet, and MCDR instance uses a symlink folder called world / current to reference the save we want to start, so we do not need to change world_names field in every plugin's config file when switching the world to start.

Here, assume the current symlink is pointing to fortress-farm folder. With this PR, QuickBackupM will copy both current symlink and fortress-farm folder to the slot, and copying them back when recovering.

When current symlink has been switched to other worlds, behavior in this PR also implies that current symlink will switch back to the world the slot saves when recovering, which is intuitive.

Fallen-Breath commented 2 years ago

Please write down the symlink logic in readme so people can know what QBM will/can do

Vigilans commented 2 years ago

@Fallen-Breath Documentation updated for symlink world's logic.