File -> RestoreableFile

This commit is contained in:
szymon 2020-11-30 10:35:27 +01:00
parent 870f133273
commit 6f9e98f104
3 changed files with 13 additions and 16 deletions

View File

@ -24,9 +24,7 @@ import net.minecraft.server.command.ServerCommandSource;
import net.szum123321.textile_backup.Statics;
import net.szum123321.textile_backup.core.restore.RestoreHelper;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.*;
public class ListBackupsCommand {
public static LiteralArgumentBuilder<ServerCommandSource> register() {
@ -40,7 +38,7 @@ public class ListBackupsCommand {
builder.append("There is only one backup available: ");
builder.append(backups.get(0).toString());
} else {
backups.sort(Comparator.comparing(RestoreHelper.RestoreableFile::getCreationTime));
backups.sort(null);
Iterator<RestoreHelper.RestoreableFile> iterator = backups.iterator();
builder.append("Available backups: ");

View File

@ -34,7 +34,6 @@ import net.minecraft.text.LiteralText;
import net.szum123321.textile_backup.Statics;
import net.szum123321.textile_backup.core.restore.RestoreHelper;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeParseException;
import java.util.Optional;
@ -88,10 +87,10 @@ public class RestoreBackupCommand {
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
Optional<File> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getMinecraftServer());
Optional<RestoreHelper.RestoreableFile> backupFile = RestoreHelper.findFileAndLockIfPresent(dateTime, source.getMinecraftServer());
if(backupFile.isPresent()) {
Statics.LOGGER.info("Found file to restore {}", backupFile.get().getName());
Statics.LOGGER.info("Found file to restore {}", backupFile.get().getFile().getName());
} else {
Statics.LOGGER.sendInfo(source, "No file created on {} was found!", dateTime.format(Statics.defaultDateTimeFormatter));

View File

@ -29,14 +29,13 @@ import net.szum123321.textile_backup.core.restore.decompressors.GenericTarDecomp
import net.szum123321.textile_backup.core.restore.decompressors.ZipDecompressor;
import java.io.File;
import java.util.NoSuchElementException;
public class RestoreBackupRunnable implements Runnable {
private final MinecraftServer server;
private final File backupFile;
private final RestoreHelper.RestoreableFile backupFile;
private final String finalBackupComment;
public RestoreBackupRunnable(MinecraftServer server, File backupFile, String finalBackupComment) {
public RestoreBackupRunnable(MinecraftServer server, RestoreHelper.RestoreableFile backupFile, String finalBackupComment) {
this.server = server;
this.backupFile = backupFile;
this.finalBackupComment = finalBackupComment;
@ -45,6 +44,7 @@ public class RestoreBackupRunnable implements Runnable {
@Override
public void run() {
Statics.LOGGER.info("Shutting down server...");
server.stop(false);
awaitServerShutdown();
@ -61,6 +61,7 @@ public class RestoreBackupRunnable implements Runnable {
File worldFile = Utilities.getWorldFolder(server);
Statics.LOGGER.info("Deleting old world...");
if(!deleteDirectory(worldFile))
Statics.LOGGER.error("Something went wrong while deleting old world!");
@ -68,16 +69,15 @@ public class RestoreBackupRunnable implements Runnable {
Statics.LOGGER.info("Starting decompression...");
if(Utilities.getFileExtension(backupFile).orElseThrow(() -> new NoSuchElementException("Couldn't get file extension!")) == ConfigHandler.ArchiveFormat.ZIP) {
ZipDecompressor.decompress(backupFile, worldFile);
} else {
GenericTarDecompressor.decompress(backupFile, worldFile);
}
if(backupFile.getArchiveFormat() == ConfigHandler.ArchiveFormat.ZIP)
ZipDecompressor.decompress(backupFile.getFile(), worldFile);
else
GenericTarDecompressor.decompress(backupFile.getFile(), worldFile);
if(Statics.CONFIG.deleteOldBackupAfterRestore) {
Statics.LOGGER.info("Deleting old backup");
if(!backupFile.delete())
if(!backupFile.getFile().delete())
Statics.LOGGER.info("Something went wrong while deleting old backup");
}