repaired bad error handling

This commit is contained in:
Szum123321 2022-10-04 18:56:48 +02:00
parent dc974aa35b
commit 53a5639373

View File

@ -61,12 +61,9 @@ public class DeleteCommand {
Path root = Utilities.getBackupRootPath(Utilities.getLevelName(source.getServer())); Path root = Utilities.getBackupRootPath(Utilities.getLevelName(source.getServer()));
RestoreableFile.applyOnFiles(root, Optional.empty(), RestoreableFile.applyOnFiles(root, Optional.empty(),
e -> { e -> log.sendErrorAL(source, "An exception occurred while trying to delete a file!", e),
log.sendError(source, "Couldn't find file by this name.");
log.sendHint(source, "Maybe try /backup list");
},
stream -> stream.filter(f -> f.getCreationTime().equals(dateTime)).map(RestoreableFile::getFile).findFirst() stream -> stream.filter(f -> f.getCreationTime().equals(dateTime)).map(RestoreableFile::getFile).findFirst()
).ifPresent(file -> { ).ifPresentOrElse(file -> {
if(Globals.INSTANCE.getLockedFile().filter(p -> p == file).isEmpty()) { if(Globals.INSTANCE.getLockedFile().filter(p -> p == file).isEmpty()) {
try { try {
Files.delete((Path) file); Files.delete((Path) file);
@ -81,6 +78,9 @@ public class DeleteCommand {
log.sendError(source, "Couldn't delete the file because it's being restored right now."); log.sendError(source, "Couldn't delete the file because it's being restored right now.");
log.sendHint(source, "If you want to abort restoration then use: /backup killR"); log.sendHint(source, "If you want to abort restoration then use: /backup killR");
} }
}, () -> {
log.sendInfo(source, "Couldn't find file by this name.");
log.sendInfo(source, "Maybe try /backup list");
} }
); );
return 0; return 0;