[#319] Delete null versions in different modes

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-01-19 12:02:08 +03:00 committed by Angira Kekteeva
parent f5d365af1d
commit 8985681493

View file

@ -570,47 +570,58 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, obj *Ver
ids []*object.ID ids []*object.ID
) )
versioningEnabled := n.isVersioningEnabled(ctx, bkt) p := &PutObjectParams{
if !versioningEnabled && obj.VersionID != unversionedObjectVersionID && obj.VersionID != "" { Object: obj.Name,
obj.Error = errors.GetAPIError(errors.ErrInvalidVersion) Reader: bytes.NewReader(nil),
return obj Header: map[string]string{},
} }
if versioningEnabled { versioningEnabled := n.isVersioningEnabled(ctx, bkt)
p := &PutObjectParams{
Object: obj.Name,
Reader: bytes.NewReader(nil),
Header: map[string]string{VersionsDeleteMarkAttr: obj.VersionID},
}
if len(obj.VersionID) != 0 {
version, err := n.checkVersionsExist(ctx, bkt, obj)
if err != nil {
obj.Error = err
return obj
}
ids = []*object.ID{version.ID}
if version.Headers[VersionsDeleteMarkAttr] == DelMarkFullObject {
obj.DeleteMarkVersion = version.Version()
}
p.Header[versionsDelAttr] = obj.VersionID // Current implementation doesn't consider "unversioned" mode (so any deletion creates "delete-mark" object).
} else { // The reason is difficulties to determinate whether versioning mode is "unversioned" or "suspended".
p.Header[VersionsDeleteMarkAttr] = DelMarkFullObject
} if obj.VersionID == unversionedObjectVersionID || !versioningEnabled && len(obj.VersionID) == 0 {
objInfo, err := n.objectPut(ctx, bkt, p) p.Header[versionsUnversionedAttr] = "true"
versions, err := n.headVersions(ctx, bkt, obj.Name)
if err != nil { if err != nil {
obj.Error = err obj.Error = err
return obj return obj
} }
if len(obj.VersionID) == 0 { last := versions.getLast(FromUnversioned())
obj.DeleteMarkVersion = objInfo.Version() if last == nil {
obj.Error = errors.GetAPIError(errors.ErrInvalidVersion)
return obj
} }
p.Header[VersionsDeleteMarkAttr] = last.Version()
for _, unversioned := range versions.unversioned() {
ids = append(ids, unversioned.ID)
}
} else if len(obj.VersionID) != 0 {
version, err := n.checkVersionsExist(ctx, bkt, obj)
if err != nil {
obj.Error = err
return obj
}
ids = []*object.ID{version.ID}
if version.Headers[VersionsDeleteMarkAttr] == DelMarkFullObject {
obj.DeleteMarkVersion = version.Version()
}
p.Header[versionsDelAttr] = obj.VersionID
p.Header[VersionsDeleteMarkAttr] = version.Version()
} else { } else {
ids, err = n.objectSearchByName(ctx, bkt.CID, obj.Name) p.Header[VersionsDeleteMarkAttr] = DelMarkFullObject
if err != nil { }
obj.Error = err
return obj objInfo, err := n.objectPut(ctx, bkt, p)
} if err != nil {
obj.Error = err
return obj
}
if len(obj.VersionID) == 0 {
obj.DeleteMarkVersion = objInfo.Version()
} }
for _, id := range ids { for _, id := range ids {