code: func (c *InstanceCache) syncState(ctx context.Context, state *messages.InstanceCache, now time.Time) error {
  	root, err := os.Open(c.fs.Root())
  	switch {
  
  	case os.IsNotExist(err):
  		state.Entries = nil
  
  	case err != nil:
  		return err
  
  	default:
  		instanceIDs, err := root.Readdirnames(0)
  		if err != nil {
  			return err
  		}
  		existingIDs := stringset.New(len(instanceIDs))
  		for _, id := range instanceIDs {
  			if common.ValidateInstanceID(id, common.AnyHash) != nil {
  				continue
  			}
  			existingIDs.Add(id)
  
  			if _, ok := state.Entries[id]; !ok {
  				if state.Entries == nil {
  					state.Entries = map[string]*messages.InstanceCache_Entry{}
  				}
  				state.Entries[id] = &messages.InstanceCache_Entry{
  					LastAccess: google.NewTimestamp(now),
  				}
  			}
  		}
  
  		for id := range state.Entries {
  			if !existingIDs.Has(id) {
  				delete(state.Entries, id)
  			}
  		}
  	}
  
  	state.LastSynced = google.NewTimestamp(now)
  	logging.Infof(ctx, "cipd: synchronized instance cache with instance files")
  	return nil
  }
docs: // syncState synchronizes the list of instances in the state file with instance
  // files.
  //
  // Preserves lastAccess of existing instances. Newly discovered files are
  // considered last accessed now.