Replaced File with Optional<File> in Statics to make sure I won't forget to check if it exists
parent
af8e14f092
commit
725d4098be
|
@ -24,6 +24,7 @@ import net.szum123321.textile_backup.core.restore.AwaitThread;
|
|||
|
||||
import java.io.File;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
@ -42,7 +43,7 @@ public class Statics {
|
|||
public static final AtomicBoolean globalShutdownBackupFlag = new AtomicBoolean(true);
|
||||
public static boolean disableWatchdog = false;
|
||||
public static AwaitThread restoreAwaitThread = null;
|
||||
public static File untouchableFile;
|
||||
public static Optional<File> untouchableFile = Optional.empty();
|
||||
|
||||
public static boolean tmpAvailable;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class DeleteCommand {
|
|||
.findFirst();
|
||||
|
||||
if(optionalFile.isPresent()) {
|
||||
if(Statics.untouchableFile == null || (Statics.untouchableFile != null && !Statics.untouchableFile.equals(optionalFile.get()))) {
|
||||
if(Statics.untouchableFile.isEmpty() || !Statics.untouchableFile.get().equals(optionalFile.get())) {
|
||||
if(optionalFile.get().delete()) {
|
||||
Statics.LOGGER.sendInfo(source, "File {} successfully deleted!", optionalFile.get().getName());
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import net.minecraft.server.command.CommandManager;
|
|||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.szum123321.textile_backup.Statics;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class KillRestoreCommand {
|
||||
public static LiteralArgumentBuilder<ServerCommandSource> register() {
|
||||
return CommandManager.literal("killR")
|
||||
|
@ -31,7 +33,7 @@ public class KillRestoreCommand {
|
|||
if(Statics.restoreAwaitThread != null && Statics.restoreAwaitThread.isAlive()) {
|
||||
Statics.restoreAwaitThread.interrupt();
|
||||
Statics.globalShutdownBackupFlag.set(true);
|
||||
Statics.untouchableFile = null;
|
||||
Statics.untouchableFile = Optional.empty();
|
||||
|
||||
Statics.LOGGER.info("{} cancelled backup restoration.", ctx.getSource().getEntity() instanceof PlayerEntity ?
|
||||
"Player: " + ctx.getSource().getName() :
|
||||
|
|
|
@ -178,7 +178,7 @@ public class BackupHelper {
|
|||
}
|
||||
|
||||
private static boolean deleteFile(File f, ServerCommandSource ctx) {
|
||||
if(!Statics.untouchableFile.equals(f)) {
|
||||
if(Statics.untouchableFile.isEmpty()|| !Statics.untouchableFile.get().equals(f)) {
|
||||
if(f.delete()) {
|
||||
Statics.LOGGER.sendInfoAL(ctx, "Deleting: {}", f.getName());
|
||||
return true;
|
||||
|
|
|
@ -45,7 +45,7 @@ public class RestoreHelper {
|
|||
.filter(rf -> rf.getCreationTime().equals(backupTime))
|
||||
.findFirst();
|
||||
|
||||
optionalFile.ifPresent(file -> Statics.untouchableFile = file.getFile());
|
||||
Statics.untouchableFile = optionalFile.map(RestoreableFile::getFile);
|
||||
|
||||
return optionalFile;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue