compress: fix crash if metadata upload failed - fixes #5994

Before this changed the backend attempted to delete a nil object if
the metadata upload failed.
This commit is contained in:
Nick Craig-Wood 2022-02-16 11:42:28 +00:00
parent 8ee0fe9863
commit 71a784cfa2

View File

@ -626,9 +626,11 @@ func (f *Fs) putMetadata(ctx context.Context, meta *ObjectMetadata, src fs.Objec
// Put the data
mo, err = put(ctx, metaReader, f.wrapInfo(src, makeMetadataName(src.Remote()), int64(len(data))), options...)
if err != nil {
removeErr := mo.Remove(ctx)
if removeErr != nil {
fs.Errorf(mo, "Failed to remove partially transferred object: %v", err)
if mo != nil {
removeErr := mo.Remove(ctx)
if removeErr != nil {
fs.Errorf(mo, "Failed to remove partially transferred object: %v", err)
}
}
return nil, err
}