Class ServerPackUpdater

  • All Implemented Interfaces:

    
    public final class ServerPackUpdater
    
                        

    Everything 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.properties that ServerPackCreator did not write and must never take — while still owing the user a pack that matches their modpack. The previous run's manifest.json is 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.

    Author:

    Griefed

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      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.
      final Boolean protects(String relativePath) Whether relativePath is covered by ApiProperties.updateProtectedPaths — matching either the entry itself or anything beneath it, so world protects the whole world.
      final Boolean preserves(File serverPack, String relativePath) Whether this run must leave serverPack/relativePath exactly as it found it: only on an update, only for a protected path, and only when the file is actually there.
      final String relativize(File serverPack, File file) file as a /-separated path relative to serverPack, or null when 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 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.
      final ServerPackManifest readManifest(File serverPack) The previous run's manifest, or null when there is none or it can not be read.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 world protects 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/relativePath exactly 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 a server.properties at 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, or null when 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.json survive.

        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 null when 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.