From 3c7ed21f74c4cdaa6a6bb568937762f28f86eb2e Mon Sep 17 00:00:00 2001
From: Pavel Karpy
Date: Wed, 15 Mar 2023 20:21:13 +0300
Subject: [PATCH] [#141] Add big object's parts to a lock object's body
That will prevent part/link object from being removed by both an external
`DELETE` call and the object expiration procedure.
Signed-off-by: Pavel Karpy
---
CHANGELOG.md | 1 +
cmd/frostfs-cli/modules/object/lock.go | 31 +++++++++++++++++++++-----
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbad19975..cc2f4adad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,6 +52,7 @@ Changelog for FrostFS Node
- Pretty printer of basic ACL in the NeoFS CLI (#2259)
- Adding of public key for nns group `group.frostfs` at init step (#130)
- Iterating over just removed files by FSTree (#98)
+- Parts of a locked object could not be removed anymore (#141)
### Removed
### Updated
diff --git a/cmd/frostfs-cli/modules/object/lock.go b/cmd/frostfs-cli/modules/object/lock.go
index 7f7da959d..e6fbedd2c 100644
--- a/cmd/frostfs-cli/modules/object/lock.go
+++ b/cmd/frostfs-cli/modules/object/lock.go
@@ -32,16 +32,35 @@ var objectLockCmd = &cobra.Command{
err := cnr.DecodeString(cidRaw)
commonCmd.ExitOnErr(cmd, "Incorrect container arg: %v", err)
+ key := key.GetOrGenerate(cmd)
+ cli := internalclient.GetSDKClientByFlag(cmd, key, commonflags.RPC)
+
oidsRaw, _ := cmd.Flags().GetStringSlice(commonflags.OIDFlag)
- lockList := make([]oid.ID, len(oidsRaw))
+ lockList := make([]oid.ID, 0, len(oidsRaw))
+ oidM := make(map[oid.ID]struct{})
- for i := range oidsRaw {
- err = lockList[i].DecodeString(oidsRaw[i])
+ for i, oidRaw := range oidsRaw {
+ var oID oid.ID
+ err = oID.DecodeString(oidRaw)
commonCmd.ExitOnErr(cmd, fmt.Sprintf("Incorrect object arg #%d: %%v", i+1), err)
- }
- key := key.GetOrGenerate(cmd)
+ if _, ok := oidM[oID]; ok {
+ continue
+ }
+
+ lockList = append(lockList, oID)
+ oidM[oID] = struct{}{}
+
+ for _, relative := range collectObjectRelatives(cmd, cli, cnr, oID) {
+ if _, ok := oidM[relative]; ok {
+ continue
+ }
+
+ lockList = append(lockList, relative)
+ oidM[relative] = struct{}{}
+ }
+ }
var idOwner user.ID
user.IDFromKey(&idOwner, key.PublicKey)
@@ -81,7 +100,7 @@ var objectLockCmd = &cobra.Command{
obj.SetPayload(lock.Marshal())
var prm internalclient.PutObjectPrm
- ReadOrOpenSession(cmd, &prm, key, cnr, nil)
+ ReadOrOpenSessionViaClient(cmd, &prm, cli, key, cnr, nil)
Prepare(cmd, &prm)
prm.SetHeader(obj)