# Buggy code
def load_linked_data(prefix, dist, rec=None):
    schannel, dname = dist2pair(dist)
    meta_file = join(prefix, "conda-meta", dname + ".json")
    if rec is None:
        try:
            with open(meta_file) as fi:
                rec = json.load(fi)
        except IOError:
            return None
    else:
        linked_data(prefix)
    url = rec.get("url")
    if "fn" not in rec:
        rec["fn"] = url.rsplit("/", 1)[-1] if url else dname + ".tar.bz2"
    if not url and "channel" in rec:
        url = rec["url"] = rec["channel"] + rec["fn"]
    if rec["fn"][:-8] != dname:
        log.debug("Ignoring invalid package metadata file: %s" % meta_file)
        return None
    channel, schannel = url_channel(url)
    rec["channel"] = channel
    rec["schannel"] = schannel
    rec["link"] = rec.get("link") or True
    cprefix = "" if schannel == "defaults" else schannel + "::"
    linked_data_[prefix][str(cprefix + dname)] = rec
    return rec


# Traceback (KeyError)
[root@42d0710d45b6 /]# conda index /opt/packages/linux-64/
updating index in: /opt/packages/linux-64
[root@42d0710d45b6 /]# ls /opt/packages/linux-64/
numpy-1.11.0-py35_1.tar.bz2  repodata.json  repodata.json.bz2
[root@42d0710d45b6 /]# conda install -c file:///opt/packages --yes numpy
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment /opt/conda:

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
numpy-1.11.0               |           py35_1         6.1 MB  file:///opt/packages

The following NEW packages will be INSTALLED:

numpy: 1.11.0-py35_1 file:///opt/packages

Pruning fetched packages from the cache ...
Fetching packages ...
numpy-1.11.0-p 100% |#########################################################################################################| Time: 0:00:00 164.40 MB/s
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 "/opt/conda/bin/conda", line 6, in <module>
sys.exit(main())
File "/opt/conda/lib/python3.5/site-packages/conda/cli/main.py", line 120, in main
args_func(args, p)
File "/opt/conda/lib/python3.5/site-packages/conda/cli/main.py", line 127, in args_func
args.func(args, p)
File "/opt/conda/lib/python3.5/site-packages/conda/cli/main_install.py", line 69, in execute
install(args, parser, 'install')
File "/opt/conda/lib/python3.5/site-packages/conda/cli/install.py", line 407, in install
execute_actions(actions, index, verbose=not args.quiet)
File "/opt/conda/lib/python3.5/site-packages/conda/plan.py", line 589, in execute_actions
inst.execute_instructions(plan, index, verbose)
File "/opt/conda/lib/python3.5/site-packages/conda/instructions.py", line 137, in execute_instructions
cmd(state, arg)
File "/opt/conda/lib/python3.5/site-packages/conda/instructions.py", line 60, in EXTRACT_CMD
extract(arg)
File "/opt/conda/lib/python3.5/site-packages/conda/install.py", line 833, in extract
rec = package_cache()[dist]
KeyError: 'file:///opt/packages::numpy-1.11.0-py35_1'

# Fixed code
def load_linked_data(prefix, dist, rec=None):
    schannel, dname = dist2pair(dist)
    meta_file = join(prefix, "conda-meta", dname + ".json")
    if rec is None:
        try:
            with open(meta_file) as fi:
                rec = json.load(fi)
        except IOError:
            return None
    else:
        linked_data(prefix)
    url = rec.get("url")
    fn = rec.get("fn")
    if not fn:
        fn = rec["fn"] = url.rsplit("/", 1)[-1] if url else dname + ".tar.bz2"
    if fn[:-8] != dname:
        log.debug("Ignoring invalid package metadata file: %s" % meta_file)
        return None
    channel = rec.get("channel")
    if channel:
        channel = channel.rstrip("/")
        if not url or (url.startswith("file:") and channel[0] != "<unknown>"):
            url = rec["url"] = channel + "/" + fn
    channel, schannel = url_channel(url)
    rec["channel"] = channel
    rec["schannel"] = schannel
    rec["link"] = rec.get("link") or True
    cprefix = "" if schannel == "defaults" else schannel + "::"
    linked_data_[prefix][str(cprefix + dname)] = rec
    return rec