fix bug replace same name file

fix file deletion while replacing file with one with the same name.
jose,
bag your pardon but don't know how to make a test.
I got it.
Give me a while to fix it.