# Buggy code
def main():
    from optparse import OptionParser

    p = OptionParser(description="conda link tool used by installer")

    p.add_option(
        "--file",
        action="store",
        help="path of a file containing distributions to link, "
        "by default all packages extracted in the cache are "
        "linked",
    )

    p.add_option(
        "--prefix",
        action="store",
        default=sys.prefix,
        help="prefix (defaults to %default)",
    )

    p.add_option("-v", "--verbose", action="store_true")

    if sys.platform == "win32":
        p.add_argument(
            "--shortcuts", action="store_true", help="Install start menu shortcuts"
        )

    opts, args = p.parse_args()
    if args:
        p.error("no arguments expected")

    logging.basicConfig()

    prefix = opts.prefix
    pkgs_dir = join(prefix, "pkgs")
    pkgs_dirs[0] = [pkgs_dir]
    if opts.verbose:
        print("prefix: %r" % prefix)

    if opts.file:
        idists = list(yield_lines(join(prefix, opts.file)))
    else:
        idists = sorted(extracted())

    linktype = (
        LINK_HARD
        if idists and try_hard_link(pkgs_dir, prefix, idists[0])
        else LINK_COPY
    )
    if opts.verbose:
        print("linktype: %s" % link_name_map[linktype])

    for dist in idists:
        if opts.verbose:
            print("linking: %s" % dist)
        link(prefix, dist, linktype, opts.shortcuts)

    messages(prefix)

    for dist in duplicates_to_remove(linked(prefix), idists):
        meta_path = join(prefix, "conda-meta", dist + ".json")
        print("WARNING: unlinking: %s" % meta_path)
        try:
            os.rename(meta_path, meta_path + ".bak")
        except OSError:
            rm_rf(meta_path)


# 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 main():
    from optparse import OptionParser

    p = OptionParser(description="conda link tool used by installer")

    p.add_option(
        "--file",
        action="store",
        help="path of a file containing distributions to link, "
        "by default all packages extracted in the cache are "
        "linked",
    )

    p.add_option(
        "--prefix",
        action="store",
        default=sys.prefix,
        help="prefix (defaults to %default)",
    )

    p.add_option("-v", "--verbose", action="store_true")

    if sys.platform == "win32":
        p.add_option(
            "--shortcuts", action="store_true", help="Install start menu shortcuts"
        )

    opts, args = p.parse_args()
    if args:
        p.error("no arguments expected")

    logging.basicConfig()

    prefix = opts.prefix
    pkgs_dir = join(prefix, "pkgs")
    pkgs_dirs[0] = [pkgs_dir]
    if opts.verbose:
        print("prefix: %r" % prefix)

    if opts.file:
        idists = list(yield_lines(join(prefix, opts.file)))
    else:
        idists = sorted(extracted())

    linktype = (
        LINK_HARD
        if idists and try_hard_link(pkgs_dir, prefix, idists[0])
        else LINK_COPY
    )
    if opts.verbose:
        print("linktype: %s" % link_name_map[linktype])

    for dist in idists:
        if opts.verbose:
            print("linking: %s" % dist)
        link(prefix, dist, linktype, opts.shortcuts)

    messages(prefix)

    for dist in duplicates_to_remove(linked(prefix), idists):
        meta_path = join(prefix, "conda-meta", dist + ".json")
        print("WARNING: unlinking: %s" % meta_path)
        try:
            os.rename(meta_path, meta_path + ".bak")
        except OSError:
            rm_rf(meta_path)