synology_apm_repo.sdk.storage.disk_space module

The free-space check before every temporary SQLite materialization (sqlite.open_sqlite’s private copy, sqlite_source.SqliteSource’s temp files), so a write never leaves the temp filesystem full.

A write proceeds only if free - in_flight >= needed + reserve; one of unknown size is checked the same way piece by piece as it writes:

  • free: shutil.disk_usage(dir).free, the bytes an unprivileged process may still write.

  • in_flight: bytes reserved by this process’s other writes to the same filesystem that haven’t finished yet.

  • reserve: the smaller of 1 GiB and total / 10 – left free for the rest of the machine.

Other processes’ writes are not seen until they land, so the check stays best-effort.

class synology_apm_repo.sdk.storage.disk_space.DiskReservation(dir_path, device, needed, free, in_flight, reserve)

Bases: object

A write’s hold on free space, from reserve_disk_space.

A write of known size holds all of it from the start; one of unknown size holds what it has written so far, growing through account(), so concurrent writes see each other’s bytes either way.

Variables:
  • dir_path – The directory checked.

  • needed – The size asked for, None when unknown.

  • free – The filesystem’s free bytes at the check.

  • in_flight – Bytes other unfinished writes held at the check.

  • reserve – The bytes kept free for the rest of the machine.

dir_path
needed
free
in_flight
reserve
account(size)

Count size more bytes about to be written.

Raises:

ResourceLimitExceededError – They would take a write past its declared needed, or an unknown-size write into the reserve or other writes’ holds.

shortfall_error(needed_bytes, *, more_than=False)

The error for a write of needed_bytes (None: undeclared) that doesn’t fit; more_than for one found mid-write to outgrow it.

synology_apm_repo.sdk.storage.disk_space.reserve_disk_space(dir_path, needed_bytes)

Check that needed_bytes fit under dir_path with the reserve left over, and hold them against this process’s other writes to that filesystem until the block exits, however it exits.

Blocking; call it from the worker thread that does the write.

Parameters:
  • dir_path (Path) – An existing directory on the filesystem written to.

  • needed_bytes (int | None) – The most the write can produce. None (unknown) holds nothing up front; the caller passes each piece to DiskReservation.account() before writing it.

Raises:

ResourceLimitExceededError – The write doesn’t fit with the reserve left free (for None, nothing is free above it).