Find sparse files
Good morning, world. Please find herein a script for detecting sparse files. This is handy if you download P2P using a client with poor staging, and your media library keeps getting littered with partial downloads. Simply run:
mike@igor$ ~/bin/sparse /media |
while read ;
do rm -i "$REPLY" ;
done
It has been tested on FreeBSD, and found to work with UFS and to not work with ZFS. It includes basic tests, which may be run with trial:
mike@igor$ trial ~/bin/sparse
Usage: ./sparse [path …]
If no arguments are supplied, ‘.’ is assumed. Check given files and recurse through given folders, printing sparse files one per line as they are encountered.
Bugs:
Does not work on ZFS partitions! du report includes sparse blocks or sparse files not being created properly.
Depends on du. Tried using os.stat().st_blocks but haven’t made sense of it.
Depends on twisted.python.filepath and twisted.trial.
UPDATE: This software is offered under certain terms and conditions. If you cannot accept these terms, you cannot use this software. The terms are as follows: I do not give a crap what you do. Try not to hurt anyone. FURTHER: fixed editing.