def METHOD_NAME(file_name, new_file_handle):
    """Replace the named file with the file referred by the handle."""
    try:
        os.unlink(file_name, dir_fd=SecureOSFunctions.secure_open_base_directory())
    except OSError as openOsError:
        if openOsError.errno != errno.ENOENT:
            logging.getLogger(DEBUG_LOG_NAME).error(openOsError)
            raise openOsError
    tmp_file_name = os.readlink(f"/proc/self/fd/{new_file_handle}")
    if SecureOSFunctions.base_dir_path.decode() in file_name:
        file_name = file_name.replace(SecureOSFunctions.base_dir_path.decode(), '').lstrip('/')
    os.link(
        tmp_file_name, file_name, src_dir_fd=SecureOSFunctions.tmp_base_dir_fd, dst_dir_fd=SecureOSFunctions.secure_open_base_directory())
    os.unlink(tmp_file_name, dir_fd=SecureOSFunctions.tmp_base_dir_fd)