In a 2016 blogpost, it is claimed:
def notActuallySafeCopy(srcfile, destfile):
if os.path.exists(destfile):
raise IOError('destination already exists')
shutil.copy(srcfile, destfile)
there is a race condition here -- there is a brief window of time after the check in which if a file is created at "destfile", it will be replaced.
... the Python documentation explicitly says that shutil.copy and shutil.copy2 can silently overwrite the destination file if it already exists, and there is no flag to prevent this.
Is this still true? Does Python supply a way to copy a file that does not overwrite a destination file?