docker/tarfile/src.go
func (s *Source) ensureCachedDataIsPresent() error {
	s.cacheDataLock.Do(func() {
		// Read and parse manifest.json
		tarManifest, err := s.loadTarManifest()
		if err != nil {
			s.cacheDataResult = err
			return
		}

		// Check to make sure length is 1
		if len(tarManifest) != 1 {
			s.cacheDataResult = errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest))
			return
		}

		// Read and parse config.
		configBytes, err := s.readTarComponent(tarManifest[0].Config)
		if err != nil {
			s.cacheDataResult = err
			return
		}
		var parsedConfig manifest.Schema2Image // There's a lot of info there, but we only really care about layer DiffIDs.
		if err := json.Unmarshal(configBytes, &parsedConfig); err != nil {
			s.cacheDataResult = errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config)
			return
		}

		knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig)
		if err != nil {
			s.cacheDataResult = err
			return
		}

		// Success; commit.
		s.tarManifest = &tarManifest[0]
		s.configBytes = configBytes
		s.configDigest = digest.FromBytes(configBytes)
		s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs
		s.knownLayers = knownLayers
	})
	return s.cacheDataResult
}
func (s *Source) ensureCachedDataIsPresent() error {
	s.cacheDataLock.Do(func() {
		// Read and parse manifest.json
		tarManifest, err := s.loadTarManifest()
		if err != nil {
			s.cacheDataResult = err
			return
		}

		// Check to make sure length is 1
		if len(tarManifest) != 1 {
			s.cacheDataResult = errors.Errorf("Unexpected tar manifest.json: expected 1 item, got %d", len(tarManifest))
			return
		}

		// Read and parse config.
		configBytes, err := s.readTarComponent(tarManifest[0].Config)
		if err != nil {
			s.cacheDataResult = err
			return
		}
		var parsedConfig manifest.Schema2Image // There's a lot of info there, but we only really care about layer DiffIDs.
		if err := json.Unmarshal(configBytes, &parsedConfig); err != nil {
			s.cacheDataResult = errors.Wrapf(err, "Error decoding tar config %s", tarManifest[0].Config)
			return
		}

		knownLayers, err := s.prepareLayerData(&tarManifest[0], &parsedConfig)
		if err != nil {
			s.cacheDataResult = err
			return
		}

		// Success; commit.
		s.tarManifest = &tarManifest[0]
		s.configBytes = configBytes
		s.configDigest = digest.FromBytes(configBytes)
		s.orderedDiffIDList = parsedConfig.RootFS.DiffIDs
		s.knownLayers = knownLayers
	})
	return s.cacheDataResult
}
// ensureCachedDataIsPresent loads data necessary for any of the public accessors.