Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ private void run() throws IOException {
this.migrateLegacyCraftBukkitPaperData(tempStorage, levelDataResult.dataTag());
tempStorage.saveAndJoin();
}
deleteMigratedSeparateRoot(this.sourceRoot);
LOGGER.info("Completed legacy CraftBukkit import for world '{}' ({})", this.context.worldName(), this.context.dimensionKey().identifier());

final Path oldSourceRoot = this.sourceRoot.resolveSibling(this.sourceRoot.getFileName() + ".old");

Files.move(this.sourceRoot, oldSourceRoot);
LOGGER.info("Completed legacy CraftBukkit import for world '{}' ({}), the old world was moved into '{}'", this.context.worldName(), this.context.dimensionKey().identifier(), oldSourceRoot);
}

private void migrateSharedSavedData() throws IOException {
Expand Down Expand Up @@ -187,18 +190,6 @@ private void copySavedDataIfPresent(
WorldMigrationSupport.copySavedDataIfPresent(this.sourceDataRoots, this.targetDataRoot, type, true);
}

private static void deleteMigratedSeparateRoot(final Path sourceRoot) throws IOException {
if (!Files.exists(sourceRoot)) {
return;
}

try (final var paths = Files.walk(sourceRoot)) {
for (final Path path : paths.sorted(java.util.Comparator.reverseOrder()).toList()) {
Files.deleteIfExists(path);
}
}
}

private @Nullable Path findExplicitFile(
final List<Path> dataRoots,
final String... relativeCandidates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.NbtException;
Expand Down Expand Up @@ -88,45 +90,31 @@ static void migrateDimensionDirectories(final Path sourceDimensionRoot, final Pa
return;
}

boolean pathsWithConflicts = false;
final HashMap<Path, Path> migrationPaths = new HashMap<>();

for (final String directory : DIMENSION_DIRECTORIES) {
final Path source = sourceDimensionRoot.resolve(directory);
if (!Files.exists(source)) {
continue;
}

final Path target = targetDimensionPath.resolve(directory);
LOGGER.info("Migrating world directory from {} to {}", source, target);
mergeMove(source, target);
}
}

private static void mergeMove(final Path source, final Path target) throws IOException {
if (Files.isDirectory(source)) {
Files.createDirectories(target);
try (final var entries = Files.list(source)) {
for (final Path child : entries.toList()) {
mergeMove(child, target.resolve(child.getFileName().toString()));
}
if (Files.exists(target)) {
pathsWithConflicts = true;
LOGGER.error("The folder '{}' already exists for dimension {}", directory, targetDimensionPath);
continue;
}
tryDeleteIfEmpty(source);
return;
migrationPaths.put(source, target);
}

if (Files.exists(target)) {
throw new IOException("Refusing to overwrite existing migrated file " + target + " while moving " + source);
if (pathsWithConflicts) {
throw new IOException("Refusing to overwrite dimension directories in " + targetDimensionPath + " while migrating from " + sourceDimensionRoot);
}

Files.createDirectories(target.getParent());
Files.move(source, target);
}

private static void tryDeleteIfEmpty(final Path path) throws IOException {
try (final var entries = Files.list(path)) {
if (entries.findAny().isPresent()) {
return;
}
for (Map.Entry<Path, Path> entry : migrationPaths.entrySet()) {
Files.move(entry.getKey(), entry.getValue());
}
Files.deleteIfExists(path);
}

record LevelDataResult(@Nullable Dynamic<?> dataTag, boolean fatalError) {}
Expand Down
Loading