clear_links as used for the --clear-links option had some broken filename generation, causing garbage data at the end. Clean up this old code, and fix this problem as a side-effect. Fixes issue #951.