code: def _rebuild(idx, path, fs, cb):
      from dvc_data.index import DataIndex, DataIndexEntry, Meta
  
      new = DataIndex()
      items = list(idx.items())
  
      cb.set_size(len(items))
      for key, entry in items:
          if entry.meta and entry.meta.isdir:
              meta = Meta(isdir=True)
          else:
              try:
                  meta = Meta.from_info(
                      fs.info(fs.join(path, *key)), fs.protocol
                  )
              except FileNotFoundError:
                  meta = None
  
          if meta:
              new.add(DataIndexEntry(key=key, meta=meta))
  
          cb.relative_update(1)
  
      return new
  
imports: from contextlib import suppress
  from dvc.exceptions import InvalidArgumentError, UploadError
  from dvc.ui import ui
  from .None import locked
label_desc: Use image node_id 1 for calling a global function with example usage: _rebuild(idx, path, fs, cb) and returns: new