Repository: conda/conda

Issue:
Scarpy
Current conda install:

               platform : win-64
          conda version : 4.3.21
       conda is private : False
      conda-env version : 4.3.21
    conda-build version : not installed
         python version : 3.6.1.final.0
       requests version : 2.14.2
       root environment : C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3  (writable)
    default environment : C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3
       envs directories : C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3\envs
                          C:\Users\dbsr7927\AppData\Local\conda\conda\envs
                          C:\Users\dbsr7927\.conda\envs
          package cache : C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3\pkgs
                          C:\Users\dbsr7927\AppData\Local\conda\conda\pkgs
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
            config file : None
             netrc file : None
           offline mode : False
             user-agent : conda/4.3.21 requests/2.14.2 CPython/3.6.1 Windows/10 Windows/10.0.14393
          administrator : False

`$ C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3\Scripts\conda-script.py install -c conda-forge scrapy`




    Traceback (most recent call last):
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\exceptions.py", line 632, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 80, in execute
        install(args, parser, 'install')
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\install.py", line 357, in install
        execute_actions(actions, index, verbose=not context.quiet)
      File "C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\plan.py", line 830, in execute_actions
        execute_instructions(plan, index, verbose)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\instructions.py", line 247, in execute_instructions
        cmd(state, arg)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\instructions.py", line 108, in UNLINKLINKTRANSACTION_CMD
        txn.execute()
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 263, in execute
        self.verify()
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 242, in verify
        self.prepare()
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 149, in prepare
        for pkg_info in self.packages_info_to_link)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 149, in <genexpr>
        for pkg_info in self.packages_info_to_link)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 54, in determine_link_type
        if hardlink_supported(source_test_file, target_prefix):
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\_vendor\auxlib\decorators.py", line 56, in _memoized_func
        result = func(*args, **kwargs)
      File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\gateways\disk\test.py", line 84, in hardlink_supported
        assert not lexists(test_file), test_file
    AssertionError: C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\.tmp.index.json


Discussion:
The code being executed here is

```python
    if lexists(test_file):
        rm_rf(test_file)
    assert not lexists(test_file), test_file
```

We definitely still have problems with `rm_rf` on Windows, perhaps related to https://github.com/conda/conda/issues/5154.
I'm submitting a PR that might fix future issues of this particular assertion error.  It's not going to fix our more general problem with `rm_rf` on windows.

In the meantime, just manually deleting `C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\.tmp.index.json` should get you on your way.

Resolving patch:
diff --git a/conda_env/cli/main_list.py b/conda_env/cli/main_list.py
--- a/conda_env/cli/main_list.py
+++ b/conda_env/cli/main_list.py
@@ -14,7 +14,7 @@
 
 
 def configure_parser(sub_parsers):
-    l = sub_parsers.add_parser(
+    list_parser = sub_parsers.add_parser(
         'list',
         formatter_class=RawDescriptionHelpFormatter,
         description=description,
@@ -22,9 +22,9 @@ def configure_parser(sub_parsers):
         epilog=example,
     )
 
-    common.add_parser_json(l)
+    common.add_parser_json(list_parser)
 
-    l.set_defaults(func=execute)
+    list_parser.set_defaults(func=execute)
 
 
 def execute(args, parser):


Test patch:
diff --git a/conda/gateways/disk/test.py b/conda/gateways/disk/test.py
--- a/conda/gateways/disk/test.py
+++ b/conda/gateways/disk/test.py
@@ -4,6 +4,7 @@
 from logging import getLogger
 from os import W_OK, access
 from os.path import basename, dirname, isdir, isfile, join, lexists
+from uuid import uuid4
 
 from .create import create_link
 from .delete import rm_rf
@@ -11,6 +12,7 @@
 from .read import find_first_existing
 from ... import CondaError
 from ..._vendor.auxlib.decorators import memoize
+from ...common.compat import text_type
 from ...common.path import expand, get_python_short_path
 from ...models.enums import LinkType
 
@@ -77,7 +79,7 @@ def hardlink_supported(source_file, dest_dir):
     # file system configuration, a symbolic link may be created
     # instead. If a symbolic link is created instead of a hard link,
     # return False.
-    test_file = join(dest_dir, '.tmp.' + basename(source_file))
+    test_file = join(dest_dir, '.tmp.%s.%s' % (basename(source_file), text_type(uuid4())[:8]))
     assert isfile(source_file), source_file
     assert isdir(dest_dir), dest_dir
     if lexists(test_file):