Please find attached v5.
What changed:
1. Now we collect which files should be kept in a separate hash table.
2. Decision whether to keep the file is made only when the file is actually missing on the source. That is, remaining WAL files will be copied over as it currently is, although it could be extremely inefficient and unnecessary.
3. Added TAP test that actually at least one file isn't removed.
Regards,
--
Alexander Kukushkin