Merge pull request #350 from fkautz/pr_out_running_gofmt_manually_auto_gofmt_didn_t_simplify_code

master
Frederick F. Kautz IV 10 years ago
commit 2191fb739f
  1. 28
      pkg/storage/donut/erasure.go

@ -121,19 +121,19 @@ func erasureGoroutine(r *io.PipeReader, eWriter erasureWriter, isClosed chan<- b
isClosed <- true isClosed <- true
} }
func (d erasureWriter) Write(data []byte) (int, error) { func (eWriter erasureWriter) Write(data []byte) (int, error) {
io.Copy(d.erasureWriter, bytes.NewBuffer(data)) io.Copy(eWriter.erasureWriter, bytes.NewBuffer(data))
return len(data), nil return len(data), nil
} }
func (d erasureWriter) Close() error { func (eWriter erasureWriter) Close() error {
d.erasureWriter.Close() eWriter.erasureWriter.Close()
<-d.isClosed <-eWriter.isClosed
return nil return nil
} }
func (d erasureWriter) CloseWithError(err error) error { func (eWriter erasureWriter) CloseWithError(err error) error {
for _, writer := range d.writers { for _, writer := range eWriter.writers {
if writer != nil { if writer != nil {
writer.CloseWithError(err) writer.CloseWithError(err)
} }
@ -141,24 +141,24 @@ func (d erasureWriter) CloseWithError(err error) error {
return nil return nil
} }
func (d erasureWriter) SetMetadata(metadata map[string]string) error { func (eWriter erasureWriter) SetMetadata(metadata map[string]string) error {
for k, _ := range metadata { for k := range metadata {
if strings.HasPrefix(k, "sys.") { if strings.HasPrefix(k, "sys.") {
return errors.New("Invalid key '" + k + "', cannot start with sys.'") return errors.New("Invalid key '" + k + "', cannot start with sys.'")
} }
} }
for k := range d.metadata { for k := range eWriter.metadata {
delete(d.metadata, k) delete(eWriter.metadata, k)
} }
for k, v := range metadata { for k, v := range metadata {
d.metadata[k] = v eWriter.metadata[k] = v
} }
return nil return nil
} }
func (d erasureWriter) GetMetadata() (map[string]string, error) { func (eWriter erasureWriter) GetMetadata() (map[string]string, error) {
metadata := make(map[string]string) metadata := make(map[string]string)
for k, v := range d.metadata { for k, v := range eWriter.metadata {
metadata[k] = v metadata[k] = v
} }
return metadata, nil return metadata, nil

Loading…
Cancel
Save