# Buggy code
def package_cache():
    """
    Initializes the package cache. Each entry in the package cache
    dictionary contains three lists:
    - urls: the URLs used to refer to that package
    - files: the full pathnames to fetched copies of that package
    - dirs: the full pathnames to extracted copies of that package
    Nominally there should be no more than one entry in each list, but
    in theory this can handle the presence of multiple copies.
    """
    if package_cache_:
        return package_cache_
    # Stops recursion
    package_cache_["@"] = None
    for pdir in pkgs_dirs:
        try:
            data = open(join(pdir, "urls.txt")).read()
            for url in data.split()[::-1]:
                if "/" in url:
                    add_cached_package(pdir, url)
        except IOError:
            pass
        for fn in os.listdir(pdir):
            add_cached_package(pdir, fn)
    del package_cache_["@"]
    return package_cache_


# Traceback (OSError)
Traceback (most recent call last):
File "/home/ilan/minonda/bin/conda-build", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/home/ilan/conda-build/bin/conda-build", line 5, in <module>
sys.exit(main())
File "/home/ilan/conda-build/conda_build/main_build.py", line 140, in main
args_func(args, p)
File "/home/ilan/conda-build/conda_build/main_build.py", line 380, in args_func
args.func(args, p)
File "/home/ilan/conda-build/conda_build/main_build.py", line 367, in execute
build.test(m)
File "/home/ilan/conda-build/conda_build/build.py", line 613, in test
rm_pkgs_cache(m.dist())
File "/home/ilan/conda-build/conda_build/build.py", line 386, in rm_pkgs_cache
plan.execute_plan(rmplan)
File "/home/ilan/conda/conda/plan.py", line 583, in execute_plan
inst.execute_instructions(plan, index, verbose)
File "/home/ilan/conda/conda/instructions.py", line 133, in execute_instructions
cmd(state, arg)
File "/home/ilan/conda/conda/instructions.py", line 65, in RM_FETCHED_CMD
install.rm_fetched(arg)
File "/home/ilan/conda/conda/install.py", line 749, in rm_fetched
rec = package_cache().get(dist)
File "/home/ilan/conda/conda/install.py", line 692, in package_cache
for fn in os.listdir(pdir):
OSError: [Errno 2] No such file or directory: '/home/ilan/minonda/pkgs'

# Fixed code
def package_cache():
    """
    Initializes the package cache. Each entry in the package cache
    dictionary contains three lists:
    - urls: the URLs used to refer to that package
    - files: the full pathnames to fetched copies of that package
    - dirs: the full pathnames to extracted copies of that package
    Nominally there should be no more than one entry in each list, but
    in theory this can handle the presence of multiple copies.
    """
    if package_cache_:
        return package_cache_
    # Stops recursion
    package_cache_["@"] = None
    for pdir in pkgs_dirs:
        try:
            data = open(join(pdir, "urls.txt")).read()
            for url in data.split()[::-1]:
                if "/" in url:
                    add_cached_package(pdir, url)
        except IOError:
            pass
        if isdir(pdir):
            for fn in os.listdir(pdir):
                add_cached_package(pdir, fn)
    del package_cache_["@"]
    return package_cache_