# Buggy code
def rename(source_path, destination_path, force=False):
    if lexists(destination_path) and force:
        rm_rf(destination_path)
    if lexists(source_path):
        log.trace("renaming %s => %s", source_path, destination_path)
        try:
            os_rename(source_path, destination_path)
        except EnvironmentError as e:
            if e.errno in (EINVAL, EXDEV):
                # see https://github.com/conda/conda/issues/6711
                log.trace(
                    "Could not rename do to errno [%s]. Falling back to copy/remove.",
                    e.errno,
                )
                _copy_then_remove(source_path, destination_path)
            else:
                raise
    else:
        log.trace("cannot rename; source path does not exist '%s'", source_path)


# Traceback (conda.CondaMultiError)
<<HTTPS 200 OK
< Accept-Ranges: bytes
< Content-Disposition: attachment; filename="six-1.11.0-py35h423b573_1.tar.bz2"; filename*=UTF-8''six-1.11.0-py35h423b573_1.tar.bz2
< Content-Type: application/x-tar
< Date: Mon, 29 Jan 2018 11:43:42 GMT
< ETag: "576d38abfcb7ceb3b323b802b1fec665"
< Last-Modified: Sat, 21 Oct 2017 18:55:29 GMT
< Server: AmazonS3
< x-amz-id-2: IGiKj9lk7QKmYRYyZCVaUEM4Ax19T3slC8e1+ZVXTR3gT5Hg9UNd/8CxoS9yDWZt5PdfORpg9mo=
< x-amz-request-id: 8A668C11FD79A607
< Content-Length: 21870
< Elapsed: 00:00.106578

TRACE conda.core.path_actions:execute(1238): extracting /opt/conda/pkgs/six-1.11.0-py35h423b573_1.tar.bz2 => /opt/conda/pkgs/six-1.11.0-py35h423b573_1
TRACE conda.gateways.disk.update:rename(60): renaming /opt/conda/pkgs/six-1.11.0-py35h423b573_1 => /opt/conda/pkgs/six-1.11.0-py35h423b573_1.c~
DEBUG conda.gateways.disk.create:extract_tarball(132): extracting /opt/conda/pkgs/six-1.11.0-py35h423b573_1.tar.bz2
to /opt/conda/pkgs/six-1.11.0-py35h423b573_1
TRACE conda.gateways.disk.create:write_as_json_to_file(61): writing json to file /opt/conda/pkgs/six-1.11.0-py35h423b573_1/info/repodata_record.json
TRACE conda.gateways.disk.create:write_as_json_to_file(61): writing json to file /opt/conda/pkgs/six-1.11.0-py35h423b573_1/info/repodata_record.json
TRACE conda.gateways.disk.delete:rm_rf(29): rm_rf /opt/conda/pkgs/six-1.11.0-py35h423b573_1.tar.bz2.c~
TRACE conda.gateways.disk.delete:rm_rf(29): rm_rf /opt/conda/pkgs/six-1.11.0-py35h423b573_1.c~
DEBUG conda.common.signals:signal_handler(56): de-registering handler for Signals.SIGIOT
DEBUG conda.common.signals:signal_handler(56): de-registering handler for Signals.SIGINT
DEBUG conda.common.signals:signal_handler(56): de-registering handler for Signals.SIGTERM
DEBUG conda.common.signals:signal_handler(56): de-registering handler for Signals.SIGQUIT
Traceback (most recent call last):
File "/opt/conda/lib/python3.5/site-packages/conda/exceptions.py", line 772, in __call__
return func(*args, **kwargs)
File "/opt/conda/lib/python3.5/site-packages/conda_env/cli/main.py", line 74, in do_call
exit_code = getattr(module, func_name)(args, parser)
File "/opt/conda/lib/python3.5/site-packages/conda_env/cli/main_update.py", line 107, in execute
installer.install(prefix, specs, args, env)
File "/opt/conda/lib/python3.5/site-packages/conda_env/installers/conda.py", line 38, in install
pfe.execute()
File "/opt/conda/lib/python3.5/site-packages/conda/core/package_cache.py", line 590, in execute
raise CondaMultiError(exceptions)
conda.CondaMultiError: [Errno 21] Is a directory: '/opt/conda/pkgs/ca-certificates-2017.08.26-h1d4fec5_0'
[Errno 21] Is a directory: '/opt/conda/pkgs/libedit-3.1-heed3624_0'

# Fixed code
def rename(source_path, destination_path, force=False):
    if lexists(destination_path) and force:
        rm_rf(destination_path)
    if lexists(source_path):
        log.trace("renaming %s => %s", source_path, destination_path)
        try:
            os_rename(source_path, destination_path)
        except EnvironmentError as e:
            if e.errno in (EINVAL, EXDEV):
                # https://github.com/conda/conda/issues/6811
                # https://github.com/conda/conda/issues/6711
                log.trace(
                    "Could not rename %s => %s due to errno [%s]. Falling back"
                    " to copy/unlink",
                    source_path,
                    destination_path,
                    e.errno,
                )
                # https://github.com/moby/moby/issues/25409#issuecomment-238537855
                # shutil.move() falls back to copy+unlink
                move(source_path, destination_path)
            else:
                raise
    else:
        log.trace("cannot rename; source path does not exist '%s'", source_path)