With great power comes great responsibility
– some guy
I recently got myself into big trouble using the force keyword. the documentation is clear, it will delete the destination. My misunderstanding was that the destination would be my source file name, i.e. it would overwrite the file if i was trying to copy over a previous version - i made the mistake of assuming it worked like unix cp, i.e. force meant it would simply overwrite the target with the same name to make updating a file with a new copy easier.
but the documentation is clear, it will DELETE THE DESTINATION. my destination was a directory full of data, and i was trying to copy a file to it. sure, i did a very dumb thing, and sure it’s convenient, but it’s a trap.
How about :
1 removing it - force the user to remove the file/directory explicitly. slightly more inconvenient but would force the user to apply a little extra thought to the process.
2 makes it’s operation more unix cp like, i.e. it will only remove something that has the same name as the source, i.e. cp(“somefile.txt”, “somedir”, force=true) will overwrite somefile.txt but won’t delete somedir.
yes, all my fault. yes it’s convenient, but I can hardly believe i’m the first person to have fallen into this trap.
just as reference neither python’s shutil copy or copyfile allow such a thing.