refactor code

This commit is contained in:
nguyenhuuluan434 2019-06-27 10:17:42 +07:00 committed by Nick Craig-Wood
parent ca324b5084
commit 940d88b695

View File

@ -1155,16 +1155,8 @@ func (o *Object) updateChunks(in0 io.Reader, headers swift.Headers, size int64,
return shouldRetryHeaders(rxHeaders, err)
})
if err != nil {
if len(segmentInfos) > 0 {
for _, v := range segmentInfos {
fs.Debugf(o, "Delete segment file %q on %q", v, o.fs.segmentsContainer)
e := o.fs.c.ObjectDelete(o.fs.segmentsContainer, v)
if e != nil {
fs.Errorf(o, "Error occured in delete segment file %q on %q , error: %q", v, o.fs.segmentsContainer, e)
}
}
deleteChunks(o, segmentInfos)
segmentInfos = nil
}
return "", err
}
i++
@ -1180,6 +1172,13 @@ func (o *Object) updateChunks(in0 io.Reader, headers swift.Headers, size int64,
return shouldRetryHeaders(rxHeaders, err)
})
if err != nil {
deleteChunks(o, segmentInfos)
segmentInfos = nil
}
return uniquePrefix + "/", err
}
func deleteChunks(o *Object, segmentInfos []string) {
if segmentInfos != nil && len(segmentInfos) > 0 {
for _, v := range segmentInfos {
fs.Debugf(o, "Delete segment file %q on %q", v, o.fs.segmentsContainer)
@ -1188,10 +1187,7 @@ func (o *Object) updateChunks(in0 io.Reader, headers swift.Headers, size int64,
fs.Errorf(o, "Error occured in delete segment file %q on %q , error: %q", v, o.fs.segmentsContainer, e)
}
}
segmentInfos = nil
}
}
return uniquePrefix + "/", err
}
// Update the object with the contents of the io.Reader, modTime and size