fix `hash-copy' on weak hash tables

Closes PR 13838
setup/cm: fix some dependency tracking on deleted files

Based on a report and patch from Tobias Hammer.