dropped unnecessary accessors in BackupContext (record)
parent
fd02df7022
commit
27aa40027c
|
@ -6,7 +6,7 @@ yarn_mappings=1.19+build.4
|
||||||
loader_version=0.14.8
|
loader_version=0.14.8
|
||||||
|
|
||||||
#Fabric api
|
#Fabric api
|
||||||
fabric_version=0.56.0+1.19
|
fabric_version=0.56.1+1.19
|
||||||
|
|
||||||
#Cloth Config
|
#Cloth Config
|
||||||
cloth_version=7.0.72
|
cloth_version=7.0.72
|
||||||
|
@ -15,12 +15,12 @@ cloth_version=7.0.72
|
||||||
modmenu_version=4.0.0
|
modmenu_version=4.0.0
|
||||||
|
|
||||||
#Lazy DFU for faster dev start
|
#Lazy DFU for faster dev start
|
||||||
lazydfu_version=0.1.2
|
lazydfu_version=v0.1.3
|
||||||
|
|
||||||
#Hash of commit form which parallel gzip will be build
|
#Hash of commit form which parallel gzip will be build
|
||||||
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
pgzip_commit_hash=af5f5c297e735f3f2df7aa4eb0e19a5810b8aff6
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 2.3.1
|
mod_version = 2.4.0
|
||||||
maven_group = net.szum123321
|
maven_group = net.szum123321
|
||||||
archives_base_name = textile_backup
|
archives_base_name = textile_backup
|
|
@ -120,7 +120,7 @@ public class TextileLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendInfo(BackupContext context, String msg, Object... args) {
|
public void sendInfo(BackupContext context, String msg, Object... args) {
|
||||||
sendInfo(context.getCommandSource(), msg, args);
|
sendInfo(context.commandSource(), msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendError(ServerCommandSource source, String msg, Object... args) {
|
public void sendError(ServerCommandSource source, String msg, Object... args) {
|
||||||
|
@ -128,7 +128,7 @@ public class TextileLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendError(BackupContext context, String msg, Object... args) {
|
public void sendError(BackupContext context, String msg, Object... args) {
|
||||||
sendError(context.getCommandSource(), msg, args);
|
sendError(context.commandSource(), msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToPlayerAndLog(Level level, ServerCommandSource source, String msg, Object... args) {
|
public void sendToPlayerAndLog(Level level, ServerCommandSource source, String msg, Object... args) {
|
||||||
|
@ -142,7 +142,7 @@ public class TextileLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendInfoAL(BackupContext context, String msg, Object... args) {
|
public void sendInfoAL(BackupContext context, String msg, Object... args) {
|
||||||
sendInfoAL(context.getCommandSource(), msg, args);
|
sendInfoAL(context.commandSource(), msg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendErrorAL(ServerCommandSource source, String msg, Object... args) {
|
public void sendErrorAL(ServerCommandSource source, String msg, Object... args) {
|
||||||
|
@ -150,6 +150,6 @@ public class TextileLogger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendErrorAL(BackupContext context, String msg, Object... args) {
|
public void sendErrorAL(BackupContext context, String msg, Object... args) {
|
||||||
sendErrorAL(context.getCommandSource(), msg, args);
|
sendErrorAL(context.commandSource(), msg, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,18 +33,6 @@ public record BackupContext(@NotNull MinecraftServer server,
|
||||||
boolean save,
|
boolean save,
|
||||||
String comment) {
|
String comment) {
|
||||||
|
|
||||||
public MinecraftServer getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerCommandSource getCommandSource() {
|
|
||||||
return commandSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionInitiator getInitiator() {
|
|
||||||
return initiator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean startedByPlayer() {
|
public boolean startedByPlayer() {
|
||||||
return initiator == ActionInitiator.Player;
|
return initiator == ActionInitiator.Player;
|
||||||
}
|
}
|
||||||
|
@ -53,14 +41,6 @@ public record BackupContext(@NotNull MinecraftServer server,
|
||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComment() {
|
|
||||||
return comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getInitiatorUUID() {
|
|
||||||
return initiator.equals(ActionInitiator.Player) && commandSource.getEntity() != null ? commandSource.getEntity().getUuid(): Util.NIL_UUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private MinecraftServer server;
|
private MinecraftServer server;
|
||||||
private ServerCommandSource commandSource;
|
private ServerCommandSource commandSource;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class BackupHelper {
|
||||||
|
|
||||||
public static Runnable create(BackupContext ctx) {
|
public static Runnable create(BackupContext ctx) {
|
||||||
if(config.get().broadcastBackupStart) {
|
if(config.get().broadcastBackupStart) {
|
||||||
Utilities.notifyPlayers(ctx.getServer(),
|
Utilities.notifyPlayers(ctx.server(),
|
||||||
"Warning! Server backup will begin shortly. You may experience some lag."
|
"Warning! Server backup will begin shortly. You may experience some lag."
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,12 +52,12 @@ public class BackupHelper {
|
||||||
|
|
||||||
builder.append("Backup started ");
|
builder.append("Backup started ");
|
||||||
|
|
||||||
builder.append(ctx.getInitiator().getPrefix());
|
builder.append(ctx.initiator().getPrefix());
|
||||||
|
|
||||||
if(ctx.startedByPlayer())
|
if(ctx.startedByPlayer())
|
||||||
builder.append(ctx.getCommandSource().getDisplayName().getString());
|
builder.append(ctx.commandSource().getDisplayName().getString());
|
||||||
else
|
else
|
||||||
builder.append(ctx.getInitiator().getName());
|
builder.append(ctx.initiator().getName());
|
||||||
|
|
||||||
builder.append(" on: ");
|
builder.append(" on: ");
|
||||||
builder.append(Utilities.getDateTimeFormatter().format(LocalDateTime.now()));
|
builder.append(Utilities.getDateTimeFormatter().format(LocalDateTime.now()));
|
||||||
|
@ -67,10 +67,10 @@ public class BackupHelper {
|
||||||
if (ctx.shouldSave()) {
|
if (ctx.shouldSave()) {
|
||||||
log.sendInfoAL(ctx, "Saving server...");
|
log.sendInfoAL(ctx, "Saving server...");
|
||||||
|
|
||||||
ctx.getServer().getPlayerManager().saveAllPlayerData();
|
ctx.server().getPlayerManager().saveAllPlayerData();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ctx.getServer().save(false, true, true);
|
ctx.server().save(false, true, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.sendErrorAL(ctx,"An exception occurred when trying to save the world!");
|
log.sendErrorAL(ctx,"An exception occurred when trying to save the world!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,32 +49,30 @@ public class MakeBackupRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Utilities.disableWorldSaving(context.getServer());
|
Utilities.disableWorldSaving(context.server());
|
||||||
Statics.disableWatchdog = true;
|
Statics.disableWatchdog = true;
|
||||||
|
|
||||||
Utilities.updateTMPFSFlag(context.getServer());
|
Utilities.updateTMPFSFlag(context.server());
|
||||||
|
|
||||||
log.sendInfoAL(context, "Starting backup");
|
log.sendInfoAL(context, "Starting backup");
|
||||||
|
|
||||||
Path world = Utilities.getWorldFolder(context.getServer());
|
Path world = Utilities.getWorldFolder(context.server());
|
||||||
|
|
||||||
log.trace("Minecraft world is: {}", world);
|
log.trace("Minecraft world is: {}", world);
|
||||||
|
|
||||||
Path outFile = Utilities
|
Path outFile = Utilities
|
||||||
.getBackupRootPath(Utilities.getLevelName(context.getServer()))
|
.getBackupRootPath(Utilities.getLevelName(context.server()))
|
||||||
.resolve(getFileName());
|
.resolve(getFileName());
|
||||||
|
|
||||||
log.trace("Outfile is: {}", outFile);
|
log.trace("Outfile is: {}", outFile);
|
||||||
|
|
||||||
// outFile.getParentFile().mkdirs();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//outFile.createNewFile();
|
|
||||||
Files.createDirectories(outFile.getParent());
|
Files.createDirectories(outFile.getParent());
|
||||||
Files.createFile(outFile);
|
Files.createFile(outFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("An exception occurred when trying to create new backup file!", e);
|
log.error("An exception occurred when trying to create new backup file!", e);
|
||||||
|
|
||||||
if(context.getInitiator() == ActionInitiator.Player)
|
if(context.initiator() == ActionInitiator.Player)
|
||||||
log.sendError(context, "An exception occurred when trying to create new backup file!");
|
log.sendError(context, "An exception occurred when trying to create new backup file!");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -92,10 +90,13 @@ public class MakeBackupRunnable implements Runnable {
|
||||||
|
|
||||||
switch (config.get().format) {
|
switch (config.get().format) {
|
||||||
case ZIP -> {
|
case ZIP -> {
|
||||||
if (coreCount > 1 && !Statics.disableTMPFiles)
|
if (coreCount > 1 && !Statics.disableTMPFiles) {
|
||||||
ParallelZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
ParallelZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||||
else
|
log.trace("Using PARALLEL Zip Compressor. Threads: {}", coreCount);
|
||||||
|
} else {
|
||||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||||
|
log.trace("Using REGULAR Zip Compressor. Threads: {}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case BZIP2 -> ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount);
|
case BZIP2 -> ParallelBZip2Compressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||||
case GZIP -> ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
case GZIP -> ParallelGzipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
||||||
|
@ -105,26 +106,20 @@ public class MakeBackupRunnable implements Runnable {
|
||||||
}
|
}
|
||||||
}.createArchive(world, outFile, context, coreCount);
|
}.createArchive(world, outFile, context, coreCount);
|
||||||
case TAR -> new AbstractTarArchiver().createArchive(world, outFile, context, coreCount);
|
case TAR -> new AbstractTarArchiver().createArchive(world, outFile, context, coreCount);
|
||||||
default -> {
|
|
||||||
log.warn("Specified compressor ({}) is not supported! Zip will be used instead!", config.get().format);
|
|
||||||
if (context.getInitiator() == ActionInitiator.Player)
|
|
||||||
log.sendError(context.getCommandSource(), "Error! No correct compression format specified! Using default compressor!");
|
|
||||||
ZipCompressor.getInstance().createArchive(world, outFile, context, coreCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BackupHelper.executeFileLimit(context.getCommandSource(), Utilities.getLevelName(context.getServer()));
|
BackupHelper.executeFileLimit(context.commandSource(), Utilities.getLevelName(context.server()));
|
||||||
|
|
||||||
if(config.get().broadcastBackupDone) {
|
if(config.get().broadcastBackupDone) {
|
||||||
Utilities.notifyPlayers(
|
Utilities.notifyPlayers(
|
||||||
context.getServer(),
|
context.server(),
|
||||||
"Done!"
|
"Done!"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log.sendInfoAL(context, "Done!");
|
log.sendInfoAL(context, "Done!");
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Utilities.enableWorldSaving(context.getServer());
|
Utilities.enableWorldSaving(context.server());
|
||||||
Statics.disableWatchdog = false;
|
Statics.disableWatchdog = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +128,7 @@ public class MakeBackupRunnable implements Runnable {
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
return Utilities.getDateTimeFormatter().format(now) +
|
return Utilities.getDateTimeFormatter().format(now) +
|
||||||
(context.getComment() != null ? "#" + context.getComment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") +
|
(context.comment() != null ? "#" + context.comment().replaceAll("[\\\\/:*?\"<>|#]", "") : "") +
|
||||||
config.get().format.getCompleteString();
|
config.get().format.getCompleteString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public abstract class AbstractCompressor {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("An exception occurred while trying to compress: {}", inputFile.relativize(file).toString(), e);
|
log.error("An exception occurred while trying to compress: {}", inputFile.relativize(file).toString(), e);
|
||||||
|
|
||||||
if (ctx.getInitiator() == ActionInitiator.Player)
|
if (ctx.initiator() == ActionInitiator.Player)
|
||||||
log.sendError(ctx, "Something went wrong while compressing files!");
|
log.sendError(ctx, "Something went wrong while compressing files!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -67,14 +67,14 @@ public abstract class AbstractCompressor {
|
||||||
For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems
|
For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems
|
||||||
In case this isn't it here's also the exception itself""", e);
|
In case this isn't it here's also the exception itself""", e);
|
||||||
|
|
||||||
if(ctx.getInitiator() == ActionInitiator.Player) {
|
if(ctx.initiator() == ActionInitiator.Player) {
|
||||||
log.sendError(ctx, "Backup failed. The file is corrupt.");
|
log.sendError(ctx, "Backup failed. The file is corrupt.");
|
||||||
log.error("For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
|
log.error("For help see: https://github.com/Szum123321/textile_backup/wiki/ZIP-Problems");
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException | ExecutionException e) {
|
} catch (IOException | InterruptedException | ExecutionException e) {
|
||||||
log.error("An exception occurred!", e);
|
log.error("An exception occurred!", e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if(ctx.getInitiator() == ActionInitiator.Player)
|
if(ctx.initiator() == ActionInitiator.Player)
|
||||||
log.sendError(ctx, "Something went wrong while compressing files!");
|
log.sendError(ctx, "Something went wrong while compressing files!");
|
||||||
} finally {
|
} finally {
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -68,13 +68,10 @@ public class RestoreBackupRunnable implements Runnable {
|
||||||
Path worldFile = Utilities.getWorldFolder(ctx.server());
|
Path worldFile = Utilities.getWorldFolder(ctx.server());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path tmp = Files.createTempDirectory (
|
Path tmp = Files.createTempDirectory(
|
||||||
worldFile.getParent(),
|
worldFile.getParent(),
|
||||||
ctx.restoreableFile().getFile().getFileName().toString());
|
ctx.restoreableFile().getFile().getFileName().toString());
|
||||||
|
|
||||||
//leave it as it is
|
|
||||||
//tmp.toFile().deleteOnExit();
|
|
||||||
|
|
||||||
log.info("Starting decompression...");
|
log.info("Starting decompression...");
|
||||||
|
|
||||||
if (ctx.restoreableFile().getArchiveFormat() == ConfigPOJO.ArchiveFormat.ZIP)
|
if (ctx.restoreableFile().getArchiveFormat() == ConfigPOJO.ArchiveFormat.ZIP)
|
||||||
|
|
Loading…
Reference in New Issue