Misc API Documentation
Provides API functions for miscellaneous or global operations.
This module contains functions that are not tied to a specific server instance, such as managing the global download cache for server executables. Operations are designed to be thread-safe.
- bedrock_server_manager.api.misc.prune_download_cache(download_dir: str, keep_count: int | None = None, app_context: AppContext | None = None) Dict[str, str]
Prunes old downloaded server archives (.zip) in a directory.
This function removes older
bedrock-server-*.zip
archive files from the specified download_dir, keeping a specified number of the most recent files. It delegates the actual pruning logic toprune_old_downloads()
.The operation uses a non-blocking lock (
_misc_lock
) to ensure thread safety; if another pruning operation is in progress, this call will be skipped, returning a “skipped” status. Triggersbefore_prune_download_cache
andafter_prune_download_cache
plugin events.- Parameters:
download_dir (str) – The path to the directory containing the downloaded server archives.
keep_count (Optional[int], optional) – The number of recent archives to keep. If
None
, the value from the global application settingretention.downloads
(defaulting to 3 if not set) is used. Defaults toNone
.
- Returns:
A dictionary with the operation result. Possible statuses: “success”, “error”, or “skipped” (if lock not acquired). Example:
{"status": "success", "message": "Download cache pruned..."}
- Return type:
Dict[str, str]
- Raises:
MissingArgumentError – If download_dir is not provided.
UserInputError – If keep_count (or the
retention.downloads
setting) is not a valid non-negative integer.BSMError – Can be raised by the underlying prune operation for issues like
AppFileNotFoundError
(if download_dir is invalid after initial checks) orFileOperationError
.