Class ServerPackUpdater
-
- All Implemented Interfaces:
public final class ServerPackUpdaterEverything that makes regenerating a server pack over an existing one safe: whether this run is an update at all, which paths it must keep its hands off, and the removal of what the previous run produced but this one did not.
It exists because a server pack is routinely run in place. The moment somebody starts a server out of the generated directory, that directory contains a world, a ban-list and a hand-tuned
server.propertiesthat ServerPackCreator did not write and must never take — while still owing the user a pack that matches their modpack. The previous run'smanifest.jsonis what makes the distinction possible: it names exactly what ServerPackCreator produced, so anything else in the directory is somebody else's, and ApiProperties.updateProtectedPaths covers the remainder, the files that came from ServerPackCreator and have been written to since.Griefed
-
-
Constructor Summary
Constructors Constructor Description ServerPackUpdater(ApiProperties apiProperties, ObjectMapper objectMapper)
-
Method Summary
Modifier and Type Method Description final BooleanisUpdateRun(File serverPack)Whether regenerating into serverPack is an update: updating must be enabled and a previous run must have left a manifest there. final Booleanprotects(String relativePath)Whether relativePath is covered by ApiProperties.updateProtectedPaths — matching either the entry itself or anything beneath it, so worldprotects the whole world.final Booleanpreserves(File serverPack, String relativePath)Whether this run must leave serverPack/relativePathexactly as it found it: only on an update, only for a protected path, and only when the file is actually there.final Stringrelativize(File serverPack, File file)file as a /-separated path relative to serverPack, ornullwhen it lies outside the pack — which is a mis-resolved destination rather than something to record, so it is logged and dropped instead of ending up in the manifest as garbage.final Unitprune(File serverPack, Set<String> produced)Removes from serverPack everything the previous run's manifest lists that produced does not — the files the modpack no longer contains — and then the directories that leaves empty, deepest first. final ServerPackManifestreadManifest(File serverPack)The previous run's manifest, or nullwhen there is none or it can not be read.-
-
Constructor Detail
-
ServerPackUpdater
ServerPackUpdater(ApiProperties apiProperties, ObjectMapper objectMapper)
- Parameters:
apiProperties- Supplies the update-toggle and the protected paths.objectMapper- Reads the previous run's manifest back.
-
-
Method Detail
-
isUpdateRun
final Boolean isUpdateRun(File serverPack)
Whether regenerating into serverPack is an update: updating must be enabled and a previous run must have left a manifest there. Without that manifest nothing can tell which files ServerPackCreator produced, so there is nothing to update — only to generate.
-
protects
final Boolean protects(String relativePath)
Whether relativePath is covered by ApiProperties.updateProtectedPaths — matching either the entry itself or anything beneath it, so
worldprotects the whole world. Separators and case are normalised first, because a manifest written on Windows carries backslashes and a pack may well be updated on another machine than it was generated on.
-
preserves
final Boolean preserves(File serverPack, String relativePath)
Whether this run must leave
serverPack/relativePathexactly as it found it: only on an update, only for a protected path, and only when the file is actually there. The last condition is what keeps a first generation able to ship a world or aserver.propertiesat all — protection guards what exists, it does not forbid creating it.
-
relativize
final String relativize(File serverPack, File file)
file as a
/-separated path relative to serverPack, ornullwhen it lies outside the pack — which is a mis-resolved destination rather than something to record, so it is logged and dropped instead of ending up in the manifest as garbage.
-
prune
final Unit prune(File serverPack, Set<String> produced)
Removes from serverPack everything the previous run's manifest lists that produced does not — the files the modpack no longer contains — and then the directories that leaves empty, deepest first. Protected paths are never touched, and neither is anything absent from the old manifest, which is how a world and an
ops.jsonsurvive.An empty produced means this run copied nothing, which is a broken run and not an empty modpack; pruning against it would delete the whole pack, so it prunes nothing instead.
-
readManifest
final ServerPackManifest readManifest(File serverPack)
The previous run's manifest, or
nullwhen there is none or it can not be read. An unreadable manifest is reported and then treated as no manifest, because the alternative — guessing — would delete files on the strength of a file we just failed to understand.
-
-
-
-