Ejemplo n.º 1
0
func (self *incubator) new(state *minos.OperationState,
	id string,
	removeIfAlreadyExisting bool) (ret retcode.Status) {

	// See if it already exists (and maybe remove it)
	_, ret = self.information(state, id)
	if !ret.IsOk() {
		return
	}
	alreadyFound := ret.Code != retcode.OkNotFound
	if alreadyFound && removeIfAlreadyExisting {
		// Ok, remove current
		ret = self.cleanIncubation(state, id)
		if !ret.IsOk() {
			return
		}
	}

	if !alreadyFound {
		// Create it
		hash := serializablehash.NewSha256()
		newState := new(incubationState)
		newState.length = 0
		newState.hashState = hash.Serialize()
		self.writeInformation(state, id, newState)

		// Create empty file
		filePath, retLocal := self.incubationFilePath(state, id)
		if !retLocal.IsOk() {
			ret = retLocal
			return
		}
		file, err := os.Create(filePath)
		if err != nil {
			err = errors.New(fmt.Sprintf("Unable to create incubation file: %v", err))
			ret = retcode.NewStatusError(retcode.ErrorServer, err)
			return
		}
		err = file.Close()
		if err != nil {
			err = errors.New(fmt.Sprintf("To close incubation file: %v", err))
			ret = retcode.NewStatusError(retcode.ErrorServer, err)
			return
		}
	}
	ret = retcode.NewStatusOk()
	return
}
Ejemplo n.º 2
0
func (self *incubationState) restoreHash() serializablehash.SerializableHash {
	hash := serializablehash.NewSha256()
	// Initialize the hash how we left it the last time
	hash.Deserialize(self.hashState)
	return hash
}