[#14] Use the Put method to update if the kludge flag is set
Some checks failed
/ DCO (pull_request) Successful in 53s
/ Builds (pull_request) Successful in 1m15s
/ Lint (pull_request) Failing after 2m7s
/ Test (pull_request) Successful in 2m59s

Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
This commit is contained in:
Aleksey Kravchenko 2025-02-17 10:57:26 +03:00
parent f630577229
commit 6e3cef40b6

View file

@ -684,10 +684,36 @@ func fillHeaders(ctx context.Context, filePath string, src fs.ObjectInfo, option
return headers
}
func (o *Object) updateWithPutImpl(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
obj, err := o.fs.Put(ctx, in, src, options...)
if err != nil {
return err
}
objInfo, ok := obj.(*Object)
if !ok {
return fmt.Errorf("invalid object type")
}
o.filePath = objInfo.filePath
o.remote = objInfo.remote
o.name = objInfo.name
o.timestamp = objInfo.timestamp
o.Object = objInfo.Object
return nil
}
// Update the Object from in with modTime and size
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
// When updating an object, the path to it should not change.
src = robject.NewStaticObjectInfo(o.Remote(), src.ModTime(ctx), src.Size(), src.Storable(), nil, src.Fs())
if o.fs.storeFilePathInFileNameAttr() {
// If the flag "kludge14" is set, the Put method should be used to update,
// as there is no Patch method in earlier versions of FrostFS.
return o.updateWithPutImpl(ctx, in, src, options...)
}
rootDirName, containerPath := bucket.Split(filepath.Join(o.fs.root, src.Remote()))
var cnrID cid.ID
var err error