WUtil: rewrote wcopy_file for better error handling and to fix Coverity #50234