func()

in pkg/store/simple_store.go [83:115]


func (s *simpleStore) Put(key string, extractor bundle.Extractor) (string, error) {
	// ensure that Put is an atomic operation
	s.mutex.Lock()
	defer s.mutex.Unlock()

	// there already exists an item, don't extract
	if item, exists := s.storeItems[key]; exists {
		// increment the item's refcount
		item.refCount++
		s.storeItems[key] = item
		return item.pathToItem, nil
	}

	// figure location to extract the files to and make the dir
	itemPath := s.getPathToItem(key)

	// create a storeItem from this
	newItem := storeItem{
		key:        key,
		refCount:   1,
		pathToItem: itemPath,
	}

	// now try to extract to the destination path
	extractErr := extractor.Extract(itemPath, s.fileSystem)
	if extractErr != nil {
		return "", extractErr
	}

	// no error, let's add it to the storeItems
	s.storeItems[key] = newItem
	return itemPath, nil
}