[#14] Use the Put method to update if the kludge flag is set
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
This commit is contained in:
parent
f630577229
commit
6e3cef40b6
1 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue