fixes #6289: avoids concurrent downloads of files with the same name and destination dir.

We seem to leak file handles here, if the lock is successful