# Buggy code
def extract(dist):
    """
    Extract a package, i.e. make a package available for linkage. We assume
    that the compressed package is located in the packages directory.
    """
    rec = package_cache()[dist]
    url = rec["urls"][0]
    fname = rec["files"][0]
    assert url and fname
    pkgs_dir = dirname(fname)
    with Locked(pkgs_dir):
        path = fname[:-8]
        temp_path = path + ".tmp"
        rm_rf(temp_path)
        with tarfile.open(fname) as t:
            t.extractall(path=temp_path)
        rm_rf(path)
        os.rename(temp_path, path)
        if sys.platform.startswith("linux") and os.getuid() == 0:
            # When extracting as root, tarfile will by restore ownership
            # of extracted files.  However, we want root to be the owner
            # (our implementation of --no-same-owner).
            for root, dirs, files in os.walk(path):
                for fn in files:
                    p = join(root, fn)
                    os.lchown(p, 0, 0)
        add_cached_package(pkgs_dir, url, overwrite=True)


# Traceback (PermissionError)
prepending C:\\Users\\Alessandro\\Anaconda3 and C:\\Users\\Alessandro\\Anaconda3
\\Library\\mingw-w64\\bin and C:\\Users\\Alessandro\\Anaconda3\\Library\\usr\\bi
n and C:\\Users\\Alessandro\\Anaconda3\\Library\\bin and C:\\Users\\Alessandro\\
Anaconda3\\Scripts to PATH

((Anaconda3)) C:\Users\Alessandro>conda info
Current conda install:

platform : win-64
conda version : 4.1.0
conda-build version : 1.20.0
python version : 3.5.1.final.0
requests version : 2.9.1
root environment : C:\Users\Alessandro\Anaconda3  (writable)
default environment : C:\Users\Alessandro\Anaconda3
envs directories : C:\Users\Alessandro\Anaconda3\envs
package cache : C:\Users\Alessandro\Anaconda3\pkgs
channel URLs : https://repo.continuum.io/pkgs/free/win-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/win-64/
https://repo.continuum.io/pkgs/pro/noarch/
config file : None
is foreign system : False


((Anaconda3)) C:\Users\Alessandro>conda create --name new_env_3 biopython
Fetching package metadata .......
Solving package specifications .............

Package plan for installation in environment C:\Users\Alessandro\Anaconda3\envs\
new_env_3:

The following NEW packages will be INSTALLED:

biopython:      1.67-np111py35_0
mkl:            11.3.3-1
numpy:          1.11.0-py35_1
pip:            8.1.2-py35_0
python:         3.5.1-4
setuptools:     23.0.0-py35_0
vs2015_runtime: 14.00.23026.0-0
wheel:          0.29.0-py35_0

Proceed ([y]/n)? y

Extracting packages ...
An unexpected error has occurred, please consider sending the            |   0%
following traceback to the conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.


Traceback (most recent call last):
File "C:\Users\Alessandro\Anaconda3\Scripts\conda-script.py", line 5, in <modu
le>
sys.exit(main())
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main.py", line
120, in main
args_func(args, p)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main.py", line
127, in args_func
args.func(args, p)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\main_create.py
", line 57, in execute
install(args, parser, 'create')
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\cli\install.py", l
ine 407, in install
execute_actions(actions, index, verbose=not args.quiet)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\plan.py", line 566
, in execute_actions
inst.execute_instructions(plan, index, verbose)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\instructions.py",
line 137, in execute_instructions
cmd(state, arg)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\instructions.py",
line 60, in EXTRACT_CMD
extract(arg)
File "C:\Users\Alessandro\Anaconda3\lib\site-packages\conda\install.py", line
821, in extract
os.rename(temp_path, path)
PermissionError: [WinError 5] Accesso negato: 'C:\\Users\\Alessandro\\Anaconda3\
\pkgs\\vs2015_runtime-14.00.23026.0-0.tmp' -> 'C:\\Users\\Alessandro\\Anaconda3\
\pkgs\\vs2015_runtime-14.00.23026.0-0'

((Anaconda3)) C:\Users\Alessandro>

# Fixed code
def extract(dist):
    """
    Extract a package, i.e. make a package available for linkage. We assume
    that the compressed package is located in the packages directory.
    """
    rec = package_cache()[dist]
    url = rec["urls"][0]
    fname = rec["files"][0]
    assert url and fname
    pkgs_dir = dirname(fname)
    with Locked(pkgs_dir):
        path = fname[:-8]
        temp_path = path + ".tmp"
        rm_rf(temp_path)
        with tarfile.open(fname) as t:
            t.extractall(path=temp_path)
        rm_rf(path)
        exp_backoff_fn(os.rename, temp_path, path)
        if sys.platform.startswith("linux") and os.getuid() == 0:
            # When extracting as root, tarfile will by restore ownership
            # of extracted files.  However, we want root to be the owner
            # (our implementation of --no-same-owner).
            for root, dirs, files in os.walk(path):
                for fn in files:
                    p = join(root, fn)
                    os.lchown(p, 0, 0)
        add_cached_package(pkgs_dir, url, overwrite=True)