Class DiskSpaceGuard

java.lang.Object
ai.attackframework.tools.burp.utils.DiskSpaceGuard

public final class DiskSpaceGuard extends Object
Enforces exporter disk-space safety rules.

The exporter should stop writing before the destination disk becomes critically full. This guard preserves a 1 GiB safety reserve on the target volume and centralizes the status/log behavior for low-disk write refusals.

When the disk/file sink is the only active sink, low disk stops export entirely via ExportReporterLifecycle.stopAndClearPendingExportWork(). When OpenSearch remains enabled, this guard refuses only the local disk write and leaves OpenSearch export running.

  • Field Details

    • MAX_MANAGED_BYTES

      public static final long MAX_MANAGED_BYTES
      Maximum managed-disk usage for spill and other exporter-owned storage.
      See Also:
    • MIN_FREE_BYTES

      public static final long MIN_FREE_BYTES
      Minimum free bytes that must remain on the destination volume after a write.
      See Also:
  • Method Details

    • ensureWritable

      public static void ensureWritable(Path target, long bytesToWrite, String context) throws IOException
      Ensures the destination volume has enough free space for a write.

      The check preserves a 1 GiB reserve after the write completes. On failure this method logs the event, posts the appropriate control status, and may stop export when the current sink selection means disk is the only active sink. Caller may invoke from any thread.

      Parameters:
      target - path being written, or its containing directory
      bytesToWrite - estimated write size in bytes
      context - short context for logs and user-facing status
      Throws:
      IOException - when the disk cannot be checked or the write should be refused
    • setUsableSpaceOverride

      public static void setUsableSpaceOverride(Function<Path,Long> override)
      Visible-for-tests override for usable space calculation.

      Tests may force low-disk scenarios without filling the real disk. Production code should leave this unset.

      Parameters:
      override - replacement usable-space resolver, or null to clear
    • resetForTests

      public static void resetForTests()
      Clears low-disk throttling state and test overrides.

      Intended for test teardown so one scenario does not leak notification state into the next test.