def reap_fileserver_cache_dir(cache_base, find_func):
 for saltenv in os.listdir(cache_base):
  env_base = os.path.join(cache_base, saltenv)
  for (root, dirs, files) in os.walk(env_base):
   if ((len(dirs) == 0) and (len(files) == 0)):
    if ((time.time() - os.path.getctime(root)) > 60):
     os.rmdir(root)
    continue
   for file_ in files:
    file_path = os.path.join(root, file_)
    file_rel_path = os.path.relpath(file_path, env_base)
    try:
     (filename, _, hash_type) = file_rel_path.rsplit('.', 2)
    except ValueError:
     log.warning('Found invalid hash file [{0}] when attempting to reap cache directory.'.format(file_))
     continue
    ret = find_func(filename, saltenv=saltenv)
    if (ret['path'] == ''):
     os.unlink(file_path)

def reap_fileserver_cache_dir ( cache_base , find_func ) : for saltenv in os . listdir ( cache_base ) : env_base = os . path . join ( cache_base , saltenv ) for ( root , dirs , files ) in os . walk ( env_base ) : if ( ( len ( dirs ) == 0 ) and ( len ( files ) == 0 ) ) : if ( ( time . time ( ) - os . path . getctime ( root ) ) > 60 ) : os . rmdir ( root ) continue for file_ in files : file_path = os . path . join ( root , file_ ) file_rel_path = os . path . relpath ( file_path , env_base ) try : ( filename , _ , hash_type ) = file_rel_path . rsplit ( '.' , 2 ) except ValueError : log . warning ( 'Found invalid hash file [{0}] when attempting to reap cache directory.' . format ( file_ ) ) continue ret = find_func ( filename , saltenv = saltenv ) if ( ret [ 'path' ] == '' ) : os . unlink ( file_path )
remove unused cache items assuming the cache directory follows a directory convention: cache_base -> saltenv -> relpath .