Fix .no_recover files never being cleaned up (fixes #497)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user