<commit_before>package rpcd

import (
	"errors"
	"fmt"
	"github.com/Symantec/Dominator/lib/hash"
	"github.com/Symantec/Dominator/proto/imageserver"
)

func (t *rpcType) AddImage(request imageserver.AddImageRequest,
	reply *imageserver.AddImageResponse) error {
	if imageDataBase.CheckImage(request.ImageName) {
		return errors.New("image already exists")
	}
	if request.Image == nil {
		return errors.New("nil image")
	}
	if request.Image.FileSystem == nil {
		return errors.New("nil file-system")
	}
	// Verify all objects are available.
	hashes := make([]hash.Hash, 0,
		len(request.Image.FileSystem.RegularInodeTable))
	for _, inode := range request.Image.FileSystem.RegularInodeTable {
		if inode.Size > 0 {
			hashes = append(hashes, inode.Hash)
		}
	}
	objectsPresent, err := imageDataBase.ObjectServer().CheckObjects(hashes)
	if err != nil {
		return err
	}
	for index, present := range objectsPresent {
		if !present {
			return errors.New(fmt.Sprintf("object: %d %x is not available",
				index, hashes[index]))
		}
	}
	// TODO(rgooch): Remove debugging output.
	fmt.Printf("AddImage(%s)\n", request.ImageName)
	return imageDataBase.AddImage(request.Image, request.ImageName)
}<commit_msg>Remove leftover debugging change.<commit_after>package rpcd

import (
	"errors"
	"fmt"
	"github.com/Symantec/Dominator/lib/hash"
	"github.com/Symantec/Dominator/proto/imageserver"
)

func (t *rpcType) AddImage(request imageserver.AddImageRequest,
	reply *imageserver.AddImageResponse) error {
	if imageDataBase.CheckImage(request.ImageName) {
		return errors.New("image already exists")
	}
	if request.Image == nil {
		return errors.New("nil image")
	}
	if request.Image.FileSystem == nil {
		return errors.New("nil file-system")
	}
	// Verify all objects are available.
	hashes := make([]hash.Hash, 0,
		len(request.Image.FileSystem.RegularInodeTable))
	for _, inode := range request.Image.FileSystem.RegularInodeTable {
		if inode.Size > 0 {
			hashes = append(hashes, inode.Hash)
		}
	}
	objectsPresent, err := imageDataBase.ObjectServer().CheckObjects(hashes)
	if err != nil {
		return err
	}
	for index, present := range objectsPresent {
		if !present {
			return errors.New(fmt.Sprintf("object: %x is not available",
				hashes[index]))
		}
	}
	// TODO(rgooch): Remove debugging output.
	fmt.Printf("AddImage(%s)\n", request.ImageName)
	return imageDataBase.AddImage(request.Image, request.ImageName)
}
{'fraction_non_alphanumeric': 0.13258520365752285, 'fraction_numerical': 0.0016625103906899418, 'mean_word_length': 4.558891454965358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2461255', 'n_tokens_mistral': 856, 'n_tokens_neox': 811, 'n_words': 171}