FormatConverter: Copy worlds for backup if rename fails

this can fail if the backups directory points to a different drive than the original worlds location. In this case, we have to copy and delete the files instead, which is much slower, but works.
I REALLY advise against putting backups on a different mount point than worlds if you plan to convert large worlds.
This commit is contained in:
Dylan K. Taylor
2021-06-17 20:45:47 +01:00
parent ec6103d61e
commit 43f71d0d63
2 changed files with 62 additions and 2 deletions

View File

@ -91,8 +91,17 @@ class FormatConverter{
$new->close();
$this->logger->info("Backing up pre-conversion world to " . $this->backupPath);
rename($path, $this->backupPath);
rename($new->getPath(), $path);
if(!@rename($path, $this->backupPath)){
$this->logger->warning("Moving old world files for backup failed, attempting copy instead. This might take a long time.");
Filesystem::recursiveCopy($path, $this->backupPath);
Filesystem::recursiveUnlink($path);
}
if(!@rename($new->getPath(), $path)){
//we don't expect this to happen because worlds/ should most likely be all on the same FS, but just in case...
$this->logger->debug("Relocation of new world files to location failed, attempting copy and delete instead");
Filesystem::recursiveCopy($new->getPath(), $path);
Filesystem::recursiveUnlink($new->getPath());
}
$this->logger->info("Conversion completed");
/**