Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify check_free_space function to verify available disk space #7760

Merged
merged 1 commit into from
Dec 8, 2023

Conversation

drew2a
Copy link
Contributor

@drew2a drew2a commented Dec 7, 2023

This PR modifies the function check_free_space to ignore OSErrors so they cannot lead to Tribler crashing.
Additionally, in the start_gui.py module, the check_free_space function now takes a parameter specifying the root state directory to be checked for free space.

Fixes #7745

@drew2a drew2a marked this pull request as ready for review December 7, 2023 15:49
@drew2a drew2a requested review from a team and qstokkink and removed request for a team December 7, 2023 15:49
logger.info('Check free space')
def check_free_space(state_dir: Path):
""" Check if there is enough free space on the disk."""
logger.info(f'Checking free space for the folder: {state_dir}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Using f-strings in logging calls is generally discouraged (see for example https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/logging-fstring-interpolation.html).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this discussion before: #5611 :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I forgot about that. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. For this PR, I left the "f-string" version, but we can discuss it at the next dev meeting. In case of an altered agreement, I'll change the formatting for all upcoming pull requests.

This commit modifies the function `check_free_space`. The function checks if there is enough free space on the disk by calculating the disk usage of a specified folder. If the available space is less than 100MB, an error message is displayed and Tribler exits. The function also logs the amount of free space when it is sufficient. Additionally, in the `start_gui.py` module, the `check_free_space` function now takes a parameter specifying the root state directory to be checked for free space.

Add test cases for check_free_space

- Added new test cases for the `check_free_space` function to ensure it works correctly when there's sufficient disk space and raises an exception when there's insufficient disk space.
- Also added test cases to check the behavior when there's an ImportError or OSError.
@drew2a drew2a merged commit da413e2 into Tribler:main Dec 8, 2023
19 checks passed
@drew2a drew2a deleted the fix/7745 branch December 8, 2023 11:06
kozlovsky pushed a commit that referenced this pull request Mar 8, 2024
…le disk space

This commit modifies the function `check_free_space`. The function checks if there is enough free space on the disk by calculating the disk usage of a specified folder. If the available space is less than 100MB, an error message is displayed and Tribler exits. The function also logs the amount of free space when it is sufficient. Additionally, in the `start_gui.py` module, the `check_free_space` function now takes a parameter specifying the root state directory to be checked for free space.

Add test cases for check_free_space

- Added new test cases for the `check_free_space` function to ensure it works correctly when there's sufficient disk space and raises an exception when there's insufficient disk space.
- Also added test cases to check the behavior when there's an ImportError or OSError.

(cherry picked from commit b2bc372)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants