Exemplo n.º 1
0
func (s *MySuite) TestWrappedError(c *C) {
	_, e := os.Stat("this-file-cannot-exit")
	es := probe.NewError(e)       // *probe.Error
	e = probe.NewWrappedError(es) // *probe.WrappedError
	_, ok := probe.ToWrappedError(e)
	c.Assert(ok, Equals, true)
}
Exemplo n.º 2
0
// readObjectData -
func (b bucket) readObjectData(objectName string, writer *io.PipeWriter, objMetadata ObjectMetadata) {
	readers, err := b.getObjectReaders(objectName, "data")
	if err != nil {
		writer.CloseWithError(probe.NewWrappedError(err))
		return
	}
	for _, reader := range readers {
		defer reader.Close()
	}
	var expected512Sum, expectedMd5sum []byte
	{
		var err error
		expectedMd5sum, err = hex.DecodeString(objMetadata.MD5Sum)
		if err != nil {
			writer.CloseWithError(probe.NewWrappedError(probe.NewError(err)))
			return
		}
		expected512Sum, err = hex.DecodeString(objMetadata.SHA512Sum)
		if err != nil {
			writer.CloseWithError(probe.NewWrappedError(probe.NewError(err)))
			return
		}
	}
	hasher := md5.New()
	sum512hasher := sha256.New()
	mwriter := io.MultiWriter(writer, hasher, sum512hasher)
	switch len(readers) > 1 {
	case true:
		if objMetadata.ErasureTechnique == "" {
			writer.CloseWithError(probe.NewWrappedError(probe.NewError(MissingErasureTechnique{})))
			return
		}
		encoder, err := newEncoder(objMetadata.DataDisks, objMetadata.ParityDisks, objMetadata.ErasureTechnique)
		if err != nil {
			writer.CloseWithError(probe.NewWrappedError(err))
			return
		}
		totalLeft := objMetadata.Size
		for i := 0; i < objMetadata.ChunkCount; i++ {
			decodedData, err := b.decodeEncodedData(totalLeft, int64(objMetadata.BlockSize), readers, encoder, writer)
			if err != nil {
				writer.CloseWithError(probe.NewWrappedError(err))
				return
			}
			if _, err := io.Copy(mwriter, bytes.NewReader(decodedData)); err != nil {
				writer.CloseWithError(probe.NewWrappedError(probe.NewError(err)))
				return
			}
			totalLeft = totalLeft - int64(objMetadata.BlockSize)
		}
	case false:
		_, err := io.Copy(writer, readers[0])
		if err != nil {
			writer.CloseWithError(probe.NewWrappedError(probe.NewError(err)))
			return
		}
	}
	// check if decodedData md5sum matches
	if !bytes.Equal(expectedMd5sum, hasher.Sum(nil)) {
		writer.CloseWithError(probe.NewWrappedError(probe.NewError(ChecksumMismatch{})))
		return
	}
	if !bytes.Equal(expected512Sum, sum512hasher.Sum(nil)) {
		writer.CloseWithError(probe.NewWrappedError(probe.NewError(ChecksumMismatch{})))
		return
	}
	writer.Close()
	return
}
Exemplo n.º 3
0
// Get auth keys
func (s *AuthService) Get(r *http.Request, args *Args, reply *AuthReply) error {
	if err := getAuth(reply); err != nil {
		return probe.NewWrappedError(err)
	}
	return nil
}
Exemplo n.º 4
0
// Set method
func (s *DonutService) Set(r *http.Request, args *DonutArgs, reply *Reply) error {
	if err := setDonut(args, reply); err != nil {
		return probe.NewWrappedError(err)
	}
	return nil
}
Exemplo n.º 5
0
// Get method
func (s *MemStatsService) Get(r *http.Request, args *Args, reply *MemStatsReply) error {
	if err := setMemStatsReply(reply); err != nil {
		return probe.NewWrappedError(err)
	}
	return nil
}
Exemplo n.º 6
0
// Get method
func (s *SysInfoService) Get(r *http.Request, args *Args, reply *SysInfoReply) error {
	if err := setSysInfoReply(reply); err != nil {
		return probe.NewWrappedError(err)
	}
	return nil
}