Fix issue of same source/destination resulting in empty file. Similar to commit 8a2646d92f5, but with less code and also enables not specifying a destination, which will set the destination to the source.