def replace_file_or_dir(dest, source):
from rez.vendor.atomicwrites import replace_atomic<EOL>if not os.path.exists(dest):<EOL><INDENT>try:<EOL><INDENT>os.rename(source, dest)<EOL>return<EOL><DEDENT>except:<EOL><INDENT>if not os.path.exists(dest):<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>replace_atomic(source, dest)<EOL>return<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>with make_tmp_name(dest) as tmp_dest:<EOL><INDENT>os.rename(dest, tmp_dest)<EOL>os.rename(source, dest)<EOL><DEDENT>
Replace `dest` with `source`.

    Acts like an `os.rename` if `dest` does not exist. Otherwise, `dest` is
    deleted and `src` is renamed to `dest`.