Class ModuleFileTransactions

java.lang.Object
com.ultikits.ultitools.utils.ModuleFileTransactions

@Internal public final class ModuleFileTransactions extends Object
The files of the module subsystem and the transactions that change them: which folder modules load from, and how /upm installs, updates or uninstalls them at the next restart.

Observation, not prediction. An update never decides before a restart whether the new JAR will load. /upm update downloads the new JAR into the transactions folder, <server root>/.ultikits/upm-transactions -- never into the modules folder -- and writes a record. At the next start, before the module class loader is built, applyBeforeLoad() moves the old JAR aside (it is kept) and puts the new one in place. After the modules have loaded, observeAfterLoad(List, Function) looks at what actually loaded: the update is committed only when the module is loaded from the new JAR at the new version, and otherwise rolled back -- the old JAR restored, the new one removed. Staging never touches the modules folder; the only change while the server runs is a rollback right after loading, which removes the JAR of a module that did not load and puts the old JAR back for the next start.

States. PENDING (staged) -> APPLIED (swapped at a start) -> COMMITTING or ROLLING_BACK (decided) -> record deleted. FAILED (the swap could not be made; nothing in the modules folder changed) is kept until the next /upm update of that module reports it. An APPLIED record found at a start means the previous start ended before the decision; nothing was observed, so it is rolled back before the modules load.

Crash safety. Every state change is written to the record atomically before the step that depends on it, and each step decides from the record plus which files exist -- the new JAR is recognised by its SHA-256, recorded when it was staged -- so running a step again after a crash completes it rather than repeating it, and never deletes a file that is not the staged JAR. Both versions are kept until the decision.

Restart-time removal. An uninstall records the files without unloading the module or deleting JARs while it runs. At the next start, before any module loads, a file is deleted only if its size, modification time and SHA-256 still match. A different file is left alone and its entry dropped; an unreadable file or one that could not be deleted stays recorded for a later start. Size and modification-time checks use checked NIO reads so an I/O failure is not mistaken for a different file. A removal is not queued if its file identity cannot be captured.

Where the records live. Under the server root, beside the credential store (transactionsFolder(File)), not under plugins/: the panel's file interface can write under plugins/ when its file writing is enabled, and a forged removal record there would delete a module JAR at the next start (maintainer decision, 2026-09-30). The price is that the start-up swap is an atomic rename between the modules folder and this folder: when plugins/ is on another file system the rename is refused, the update is not applied, and one SEVERE line names both folders. There is deliberately no copy fallback -- a copy is not atomic, and the crash-window guarantees below rely on every move being a rename.

Confinement. A record names files only by their file name. Each name is resolved against the one folder it belongs to and canonicalised; a name that leaves that folder -- a separator, .., or a link pointing elsewhere -- makes the whole record refused with a warning, so a crafted record cannot move or delete an arbitrary file. The transaction's own working folder is derived from a hash of the record's type and key, never read from the record.

Since:
6.3.0