diff --git a/core/services/kraken/kraken.py b/core/services/kraken/kraken.py index 01a6eb63b6..3220175966 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 + async def has_enough_disk_space(self, path: str = "/", required: int = 1073741824) -> 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 free_space > required + 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 958400cce6..8850363dfa 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))