Fix .no_recover files never being cleaned up (fixes #497)

This commit is contained in:
Jonas Herzig
2021-08-15 11:28:11 +02:00
parent 110199044f
commit 3db8c28505
2 changed files with 17 additions and 1 deletions

View File

@@ -325,6 +325,18 @@ public class ReplayMod implements Module, Scheduler {
} catch (IOException e) {
e.printStackTrace();
}
// Cleanup leftover no_recover files
try (DirectoryStream<Path> paths = Files.newDirectoryStream(getReplayFolder())) {
for (Path path : paths) {
String name = path.getFileName().toString();
if (name.endsWith(".no_recover")) {
Files.delete(path);
}
}
} catch (IOException e) {
e.printStackTrace();
}
});
}

View File

@@ -275,7 +275,8 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
// If we crash right here, on the next start we'll prompt the user for recovery
// but we don't really want that, so drop a marker file to skip recovery for this replay.
Files.createFile(outputPath.resolveSibling(outputPath.getFileName() + ".no_recover"));
Path noRecoverMarker = outputPath.resolveSibling(outputPath.getFileName() + ".no_recover");
Files.createFile(noRecoverMarker);
// We still have the replay, so we just save it (at least for a few weeks) in case they change their mind
String replayName = FilenameUtils.getBaseName(outputPath.getFileName().toString());
@@ -287,6 +288,9 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
Files.createDirectories(rawPath.getParent());
replayFile.saveTo(rawPath.toFile());
replayFile.close();
// Done, clean up the marker
Files.delete(noRecoverMarker);
return;
}