Repository: conda/conda

Issue:
Package cache error with conda 4.3.12 on win64
Following error occurs when I try to create a new environment with conda 4.3.12 on win64:

    `$ C:\Program Files\Anaconda3\Scripts\conda-script.py create -p C:\hub\temp\venv python=3.5`

    Traceback (most recent call last):
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\exceptions.py", line 616, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\main_create.py", line 68, in execute
        install(args, parser, 'create')
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\install.py", line 222, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 125, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 558, in fetch_index
        repodatas = _collect_repodatas(use_cache, tasks)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 547, in _collect_repodatas
        repodatas = _collect_repodatas_serial(use_cache, tasks)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 520, in _collect_repodatas_serial
        for url, schan, pri in tasks]
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 520, in <listcomp>
        for url, schan, pri in tasks]
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 144, in func
        res = f(*args, **kwargs)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 464, in fetch_repodata
        cache_path = join(cache_dir or create_cache_dir(), cache_fn_url(url))
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 596, in create_cache_dir
        assert pkgs_dir == context.pkgs_dirs[0], (pkgs_dir, context.pkgs_dirs)
    AssertionError: ('C:\\Users\\xxx\\AppData\\Local\\conda\\conda\\pkgs', ('C:\\Program Files\\Anaconda3\\pkgs', 'C:\\Users\\xxx\\AppData\\Local\\conda\\conda\\pkgs'))

Conda info is:

               platform : win-64
          conda version : 4.3.12
       conda is private : False
      conda-env version : 4.3.12
    conda-build version : 2.1.4
         python version : 3.6.0.final.0
       requests version : 2.12.4
       root environment : C:\Program Files\Anaconda3  (read only)
    default environment : C:\Program Files\Anaconda3
       envs directories : C:\Program Files\Anaconda3\envs
                          C:\Users\xxx\AppData\Local\conda\conda\envs
                          C:\Users\xxx\.conda\envs
          package cache : C:\Program Files\Anaconda3\pkgs
                          C:\Users\xxx\AppData\Local\conda\conda\pkgs
           channel URLs : [...]
            config file : C:\Program Files\Anaconda3\.condarc
           offline mode : False
             user-agent : conda/4.3.12 requests/2.12.4 CPython/3.6.0 Windows/10 Windows/10.0.10240

Somehow the program files cache dir is prioritized even if it is not writable. 
Works with 4.3.9, throws a different error with 4.3.11 (part of the stack trace below)

      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 494, in fetch_repodata
        touch(cache_path)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\gateways\disk\update.py", line 64, in touch
        utime(path, None)
    PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Anaconda3\\pkgs\\cache\\3e904a53.json'
Package cache error with conda 4.3.12 on win64
Following error occurs when I try to create a new environment with conda 4.3.12 on win64:

    `$ C:\Program Files\Anaconda3\Scripts\conda-script.py create -p C:\hub\temp\venv python=3.5`

    Traceback (most recent call last):
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\exceptions.py", line 616, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\main_create.py", line 68, in execute
        install(args, parser, 'create')
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\cli\install.py", line 222, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 125, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 558, in fetch_index
        repodatas = _collect_repodatas(use_cache, tasks)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 547, in _collect_repodatas
        repodatas = _collect_repodatas_serial(use_cache, tasks)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 520, in _collect_repodatas_serial
        for url, schan, pri in tasks]
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 520, in <listcomp>
        for url, schan, pri in tasks]
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 144, in func
        res = f(*args, **kwargs)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 464, in fetch_repodata
        cache_path = join(cache_dir or create_cache_dir(), cache_fn_url(url))
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 596, in create_cache_dir
        assert pkgs_dir == context.pkgs_dirs[0], (pkgs_dir, context.pkgs_dirs)
    AssertionError: ('C:\\Users\\xxx\\AppData\\Local\\conda\\conda\\pkgs', ('C:\\Program Files\\Anaconda3\\pkgs', 'C:\\Users\\xxx\\AppData\\Local\\conda\\conda\\pkgs'))

Conda info is:

               platform : win-64
          conda version : 4.3.12
       conda is private : False
      conda-env version : 4.3.12
    conda-build version : 2.1.4
         python version : 3.6.0.final.0
       requests version : 2.12.4
       root environment : C:\Program Files\Anaconda3  (read only)
    default environment : C:\Program Files\Anaconda3
       envs directories : C:\Program Files\Anaconda3\envs
                          C:\Users\xxx\AppData\Local\conda\conda\envs
                          C:\Users\xxx\.conda\envs
          package cache : C:\Program Files\Anaconda3\pkgs
                          C:\Users\xxx\AppData\Local\conda\conda\pkgs
           channel URLs : [...]
            config file : C:\Program Files\Anaconda3\.condarc
           offline mode : False
             user-agent : conda/4.3.12 requests/2.12.4 CPython/3.6.0 Windows/10 Windows/10.0.10240

Somehow the program files cache dir is prioritized even if it is not writable. 
Works with 4.3.9, throws a different error with 4.3.11 (part of the stack trace below)

      File "C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py", line 494, in fetch_repodata
        touch(cache_path)
      File "C:\Program Files\Anaconda3\lib\site-packages\conda\gateways\disk\update.py", line 64, in touch
        utime(path, None)
    PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Anaconda3\\pkgs\\cache\\3e904a53.json'


Discussion:
@wulmer Thanks for the report.  That `assert` is incorrect, and it was a mistake that it got left in.  Can you do me a favor and edit your file

    C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py

by removing the `assert` on line `596`?  See if that fixes your issue...
Thanks for using canary btw :)
> Somehow the program files cache dir is prioritized even if it is not writable

It's being correctly recognized now as a read-only cache.  The "first writable cache" is `C:\Users\xxx\AppData\Local\conda\conda\pkgs`, which is why that assert statement is incorrect.
@wulmer Thanks for the report.  That `assert` is incorrect, and it was a mistake that it got left in.  Can you do me a favor and edit your file

    C:\Program Files\Anaconda3\lib\site-packages\conda\core\index.py

by removing the `assert` on line `596`?  See if that fixes your issue...
Thanks for using canary btw :)
> Somehow the program files cache dir is prioritized even if it is not writable

It's being correctly recognized now as a read-only cache.  The "first writable cache" is `C:\Users\xxx\AppData\Local\conda\conda\pkgs`, which is why that assert statement is incorrect.

Resolving patch:
diff --git a/conda/core/index.py b/conda/core/index.py
--- a/conda/core/index.py
+++ b/conda/core/index.py
@@ -591,8 +591,6 @@ def add_http_value_to_dict(resp, http_key, d, dict_key):
 
 
 def create_cache_dir():
-    pkgs_dir = PackageCache.first_writable(context.pkgs_dirs).pkgs_dir
-    assert pkgs_dir == context.pkgs_dirs[0], (pkgs_dir, context.pkgs_dirs)
     cache_dir = join(PackageCache.first_writable(context.pkgs_dirs).pkgs_dir, 'cache')
     try:
         makedirs(cache_dir)


Test patch: