Skip to content

Commit

Permalink
create the directory if it does not exist when checking disk space (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
severo authored Apr 17, 2024
1 parent 3a8fff7 commit abca742
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion libs/libapi/src/libapi/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ def get_download_folder(


def check_available_disk_space(path: StrPath, required_space: int) -> None:
disk_stat = os.statvfs(path)
try:
disk_stat = os.statvfs(path)
except FileNotFoundError:
# The path does not exist, we create it and
init_dir(path)
disk_stat = os.statvfs(path)
# Calculate free space in bytes
free_space = disk_stat.f_bavail * disk_stat.f_frsize
logging.debug(f"{free_space} available space, needed {required_space}")
Expand Down
10 changes: 9 additions & 1 deletion libs/libapi/tests/test_duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from pytest import TempPathFactory

from libapi.duckdb import get_index_file_location_and_download_if_missing
from libapi.duckdb import check_available_disk_space, get_index_file_location_and_download_if_missing


@pytest.mark.parametrize("partial_index", [False, True])
Expand Down Expand Up @@ -57,3 +57,11 @@ def download_index_file(
args, kwargs = download_mock.call_args
assert not args
assert kwargs["repo_file_location"] == expected_repo_file_location


@pytest.mark.parametrize("subpath", [None, "does_not_exist"])
def test_check_available_disk_space(tmp_path_factory: TempPathFactory, subpath: Optional[str]) -> None:
path = tmp_path_factory.mktemp("test_check_available_disk_space")
if subpath:
path = path / subpath
check_available_disk_space(path=path, required_space=1)

0 comments on commit abca742

Please sign in to comment.