diff --git a/core/services/kraken/kraken.py b/core/services/kraken/kraken.py index 01a6eb63b..640e47791 100644 --- a/core/services/kraken/kraken.py +++ b/core/services/kraken/kraken.py @@ -346,5 +346,13 @@ async def load_stats(self) -> Dict[str, Any]: } return result + def has_enough_disk_space(self, path: str = "/", required_mb: int = 2**10) -> bool: + try: + free_space = psutil.disk_usage(path).free + # Right now only check if there is 1GB of free space as a hardcoded value + return bool(free_space > required_mb * 2**20) + except FileNotFoundError: + return False + async def stop(self) -> None: self.should_run = False diff --git a/core/services/kraken/main.py b/core/services/kraken/main.py index 958400cce..8850363df 100755 --- a/core/services/kraken/main.py +++ b/core/services/kraken/main.py @@ -78,6 +78,11 @@ async def install_extension(extension: Extension) -> Any: status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid extension description", ) + if not kraken.has_enough_disk_space(): + raise HTTPException( + status_code=status.HTTP_507_INSUFFICIENT_STORAGE, + detail="Not enough disk space to install the extension", + ) return StreamingResponse(kraken.install_extension(extension))