# Buggy code
def __init__(self, opts, valid_providers=VALID_PROVIDERS, cache_root=None):
    self.opts = opts
    self.valid_providers = valid_providers
    self.get_provider()
    if cache_root is not None:
        self.cache_root = cache_root
    else:
        self.cache_root = os.path.join(self.opts["cachedir"], self.role)
    self.env_cache = os.path.join(self.cache_root, "envs.p")
    self.hash_cachedir = os.path.join(self.cache_root, self.role, "hash")
    self.file_list_cachedir = os.path.join(
        self.opts["cachedir"], "file_lists", self.role
    )


# Traceback (IOError)
Sep 17 18:55:12 [DEBUG   ] LazyLoaded local_cache.clean_old_jobs
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Updating fileserver for git_pillar module
Sep 17 18:55:12 [DEBUG   ] Could not LazyLoad config.merge
Sep 17 18:55:12 [DEBUG   ] Updating git fileserver cache
Sep 17 18:55:12 [DEBUG   ] gitfs removed old cachedir /var/cache/salt/master/gitfs/gitfs
Sep 17 18:55:12 [INFO    ] Wrote new gitfs remote map to /var/cache/salt/master/gitfs/remote_map.txt
Sep 17 18:55:12 [DEBUG   ] Set lock for file:///repo.git
Sep 17 18:55:12 [DEBUG   ] gitfs is fetching from 'file:///repo.git'
Sep 17 18:55:12 [ERROR   ] Error in function _file_hash:
Sep 17 18:55:12 Traceback (most recent call last):
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1379, in run_func
Sep 17 18:55:12     ret = getattr(self, func)(load)
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 528, in file_hash
Sep 17 18:55:12     fnd = self.find_file(load['path'], load['saltenv'])
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/fileserver/__init__.py", line 482, in find_file
Sep 17 18:55:12     fnd = self.servers[fstr](path, saltenv, **kwargs)
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 143, in find_file
Sep 17 18:55:12     return gitfs.find_file(path, tgt_env=tgt_env, **kwargs)
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 2100, in find_file
Sep 17 18:55:12     with salt.utils.fopen(lk_fn, 'w+') as fp_:
Sep 17 18:55:12   File "/usr/lib/python2.7/dist-packages/salt/utils/__init__.py", line 1208, in fopen
Sep 17 18:55:12     fhandle = open(*args, **kwargs)
Sep 17 18:55:12 IOError: [Errno 2] No such file or directory: '/var/cache/salt/master/gitfs/gitfs/hash/path/to/my/file.jinja.lk'
Sep 17 18:55:12 [DEBUG   ] Removed lock for file:///repo.git

# Fixed code
def __init__(self, opts, valid_providers=VALID_PROVIDERS, cache_root=None):
    self.opts = opts
    self.valid_providers = valid_providers
    self.get_provider()
    if cache_root is not None:
        self.cache_root = cache_root
    else:
        self.cache_root = os.path.join(self.opts["cachedir"], self.role)
    self.env_cache = os.path.join(self.cache_root, "envs.p")
    self.hash_cachedir = os.path.join(self.cache_root, "hash")
    self.file_list_cachedir = os.path.join(
        self.opts["cachedir"], "file_lists", self.role
    )