Running tmt clean will now show disk space freed#4801
Running tmt clean will now show disk space freed#4801AthreyVinay wants to merge 3 commits intomainfrom
tmt clean will now show disk space freed#4801Conversation
There was a problem hiding this comment.
Code Review
This pull request implements disk space reporting for the clean command by adding utilities to calculate and format file sizes. The cleaning logic for workdirs and testcloud images now logs the amount of space freed, supported by new test assertions. Feedback recommends using lstat to prevent symlink traversal during size calculation and employing floating-point arithmetic in format_size to ensure accurate unit conversion.
| from tmt.hardware import Size | ||
|
|
||
|
|
||
| def format_size(size: int) -> str: |
There was a problem hiding this comment.
Use tmt.hardware.UNITS instead: tmt.hardware.UNITS(f'{size} bytes').to_compact()
| return successful | ||
|
|
||
| def _clean_workdir(self, path: Path) -> bool: | ||
| def _clean_workdir(self, path: Path, size: int) -> bool: |
There was a problem hiding this comment.
Computing the size outside of _clean_workdir and just let it print out is very weird. We can change the return value of _clean_workdir, to e.g. a tuple of (success, size). _clean_workdir would collect the size, and just tell its caller how much data it did/would remove.
There was a problem hiding this comment.
Absolutely - that was my intuition too. The only reason was I was trying to avoid returning a tuple - and I thought dataclass would be an overkill. Will revert to returning a tuple instead.
resolves: #4593
Pull Request Checklist