lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Fix: Recursively calculate directory size in `size_of_dir`

Open maradini77 opened this issue 1 month ago • 1 comments

Fixed size_of_dir_entry to recursively calculate the size of directories. Previously, the function only returned the metadata size of directory entries (typically a few KB), completely ignoring files within subdirectories. This caused size_of_dir to return incorrect sizes for any directory tree with nested folders.

The fix checks if an entry is a directory and recursively calls size_of_dir to sum up all file sizes within the directory tree.

maradini77 avatar Nov 21 '25 15:11 maradini77

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] avatar Nov 21 '25 15:11 cla-assistant[bot]

Please rebase your change on unstable.

michaelsproul avatar Dec 15 '25 04:12 michaelsproul

@maradini77 Do you have any thoughts on the above?

michaelsproul avatar Dec 15 '25 05:12 michaelsproul

@michaelsproul Thanks for the careful review. Agreed: symlinks won’t cause an infinite loop because is_dir is false on them. I added recursion to avoid hidden bugs if the data directory ever stops being flat (e.g., future tools/plugins). To reduce DoS risk from deep nesting, I can switch to an iterative walk with a depth/entry cap and skip symlinks. Would you be comfortable if I add those protections?

maradini77 avatar Dec 15 '25 13:12 maradini77

@maradini77 Yeah let's make it iterative and capped, sounds good!

michaelsproul avatar Dec 15 '25 21:12 michaelsproul

@maradini77 Yeah let's make it iterative and capped, sounds good!

@michaelsproul updated

maradini77 avatar Dec 15 '25 21:12 maradini77

Some required checks have failed. Could you please take a look @maradini77? 🙏

mergify[bot] avatar Dec 18 '25 11:12 mergify[bot]

@michaelsproul fmt fuxed

maradini77 avatar Dec 18 '25 11:12 maradini77