original_docstring: 
          Find the first file to match the path and ref, read the file out of git
          and send the path to the newly cached file
          
docstring: Find the first file to match the path and ref, read the file out of git
  and send the path to the newly cached file
docstring_tokens: Find the first file to match the path and ref read the file out of git and send the path to the newly cached file
code: def find_file(self, path, tgt_env='base', **kwargs):  # pylint: disable=W0613
          '''
          Find the first file to match the path and ref, read the file out of git
          and send the path to the newly cached file
          '''
          fnd = {'path': '',
                 'rel': ''}
          if os.path.isabs(path) or \
                  (not salt.utils.is_hex(tgt_env) and tgt_env not in self.envs()):
              return fnd
  
          dest = salt.utils.path_join(self.cache_root, 'refs', tgt_env, path)
          hashes_glob = salt.utils.path_join(self.hash_cachedir,
                                             tgt_env,
                                             '{0}.hash.*'.format(path))
          blobshadest = salt.utils.path_join(self.hash_cachedir,
                                             tgt_env,
                                             '{0}.hash.blob_sha1'.format(path))
          lk_fn = salt.utils.path_join(self.hash_cachedir,
                                       tgt_env,
                                       '{0}.lk'.format(path))
          destdir = os.path.dirname(dest)
          hashdir = os.path.dirname(blobshadest)
          if not os.path.isdir(destdir):
              try:
                  os.makedirs(destdir)
              except OSError:
                  # Path exists and is a file, remove it and retry
                  os.remove(destdir)
                  os.makedirs(destdir)
          if not os.path.isdir(hashdir):
              try:
                  os.makedirs(hashdir)
              except OSError:
                  # Path exists and is a file, remove it and retry
                  os.remove(hashdir)
                  os.makedirs(hashdir)
  
          for repo in self.remotes:
              if repo.mountpoint(tgt_env) \
                      and not path.startswith(repo.mountpoint(tgt_env) + os.sep):
                  continue
              repo_path = path[len(repo.mountpoint(tgt_env)):].lstrip(os.sep)
              if repo.root(tgt_env):
                  repo_path = salt.utils.path_join(repo.root(tgt_env), repo_path)
  
              blob, blob_hexsha, blob_mode = repo.find_file(repo_path, tgt_env)
              if blob is None:
                  continue
  
              def _add_file_stat(fnd, mode):
                  '''
                  Add a the mode to the return dict. In other fileserver backends
                  we stat the file to get its mode, and add the stat result
                  (passed through list() for better serialization) to the 'stat'
                  key in the return dict. However, since we aren't using the
                  stat result for anything but the mode at this time, we can
                  avoid unnecessary work by just manually creating the list and
                  not running an os.stat() on all files in the repo.
                  '''
                  if mode is not None:
                      fnd['stat'] = [mode]
                  return fnd
  
              salt.fileserver.wait_lock(lk_fn, dest)
              if os.path.isfile(blobshadest) and os.path.isfile(dest):
                  with salt.utils.fopen(blobshadest, 'r') as fp_:
                      sha = fp_.read()
                      if sha == blob_hexsha:
                          fnd['rel'] = path
                          fnd['path'] = dest
                          return _add_file_stat(fnd, blob_mode)
              with salt.utils.fopen(lk_fn, 'w+') as fp_:
                  fp_.write('')
              for filename in glob.glob(hashes_glob):
                  try:
                      os.remove(filename)
                  except Exception:
                      pass
              # Write contents of file to their destination in the FS cache
              repo.write_file(blob, dest)
              with salt.utils.fopen(blobshadest, 'w+') as fp_:
                  fp_.write(blob_hexsha)
              try:
                  os.remove(lk_fn)
              except OSError:
                  pass
              fnd['rel'] = path
              fnd['path'] = dest
              return _add_file_stat(fnd, blob_mode)
  
          # No matching file was found in tgt_env. Return a dict with empty paths
          # so the calling function knows the file could not be found.
          return fnd
code_tokens: def find_file ( self , path , tgt_env = 'base' , ** kwargs ) : fnd = { 'path' : '' , 'rel' : '' } if os . path . isabs ( path ) or ( not salt . utils . is_hex ( tgt_env ) and tgt_env not in self . envs ( ) ) : return fnd dest = salt . utils . path_join ( self . cache_root , 'refs' , tgt_env , path ) hashes_glob = salt . utils . path_join ( self . hash_cachedir , tgt_env , '{0}.hash.*' . format ( path ) ) blobshadest = salt . utils . path_join ( self . hash_cachedir , tgt_env , '{0}.hash.blob_sha1' . format ( path ) ) lk_fn = salt . utils . path_join ( self . hash_cachedir , tgt_env , '{0}.lk' . format ( path ) ) destdir = os . path . dirname ( dest ) hashdir = os . path . dirname ( blobshadest ) if not os . path . isdir ( destdir ) : try : os . makedirs ( destdir ) except OSError : os . remove ( destdir ) os . makedirs ( destdir ) if not os . path . isdir ( hashdir ) : try : os . makedirs ( hashdir ) except OSError : os . remove ( hashdir ) os . makedirs ( hashdir ) for repo in self . remotes : if repo . mountpoint ( tgt_env ) and not path . startswith ( repo . mountpoint ( tgt_env ) + os . sep ) : continue repo_path = path [ len ( repo . mountpoint ( tgt_env ) ) : ] . lstrip ( os . sep ) if repo . root ( tgt_env ) : repo_path = salt . utils . path_join ( repo . root ( tgt_env ) , repo_path ) blob , blob_hexsha , blob_mode = repo . find_file ( repo_path , tgt_env ) if blob is None : continue def _add_file_stat ( fnd , mode ) : '''
                  Add a the mode to the return dict. In other fileserver backends
                  we stat the file to get its mode, and add the stat result
                  (passed through list() for better serialization) to the 'stat'
                  key in the return dict. However, since we aren't using the
                  stat result for anything but the mode at this time, we can
                  avoid unnecessary work by just manually creating the list and
                  not running an os.stat() on all files in the repo.
                  ''' if mode is not None : fnd [ 'stat' ] = [ mode ] return fnd salt . fileserver . wait_lock ( lk_fn , dest ) if os . path . isfile ( blobshadest ) and os . path . isfile ( dest ) : with salt . utils . fopen ( blobshadest , 'r' ) as fp_ : sha = fp_ . read ( ) if sha == blob_hexsha : fnd [ 'rel' ] = path fnd [ 'path' ] = dest return _add_file_stat ( fnd , blob_mode ) with salt . utils . fopen ( lk_fn , 'w+' ) as fp_ : fp_ . write ( '' ) for filename in glob . glob ( hashes_glob ) : try : os . remove ( filename ) except Exception : pass repo . write_file ( blob , dest ) with salt . utils . fopen ( blobshadest , 'w+' ) as fp_ : fp_ . write ( blob_hexsha ) try : os . remove ( lk_fn ) except OSError : pass fnd [ 'rel' ] = path fnd [ 'path' ] = dest return _add_file_stat ( fnd , blob_mode ) return fnd
short_docstring: Find the first file to match the path and ref, read the file out of git
  and send the path to the newly cached file
short_docstring_tokens: Find the first file to match the path and ref read the file out of git and send the path to the newly cached file
comment: # pylint: disable=W0613$SEP$'''
          Find the first file to match the path and ref, read the file out of git
          and send the path to the newly cached file
          '''$SEP$# Path exists and is a file, remove it and retry$SEP$# Path exists and is a file, remove it and retry$SEP$'''
                  Add a the mode to the return dict. In other fileserver backends
                  we stat the file to get its mode, and add the stat result
                  (passed through list() for better serialization) to the 'stat'
                  key in the return dict. However, since we aren't using the
                  stat result for anything but the mode at this time, we can
                  avoid unnecessary work by just manually creating the list and
                  not running an os.stat() on all files in the repo.
                  '''$SEP$# Write contents of file to their destination in the FS cache$SEP$# No matching file was found in tgt_env. Return a dict with empty paths$SEP$# so the calling function knows the file could not be found.