storj: fix uploading to the wrong object on Update with overriden remote name

In this commit we discovered a problem with objects being uploaded to
the incorrect object name. It added an integration test for the
problem.

65b2e378e0 drive: fix incorrect remote after Update on object

This test was tripped by the Storj backend and this patch fixes the
problem.
This commit is contained in:
Nick Craig-Wood 2023-06-27 12:46:55 +01:00
parent 4b4198522d
commit 389565f5e2
2 changed files with 11 additions and 7 deletions

View File

@ -528,7 +528,11 @@ func (f *Fs) NewObject(ctx context.Context, relative string) (_ fs.Object, err e
// May create the object even if it returns an error - if so will return the // May create the object even if it returns an error - if so will return the
// object and the error, otherwise will return nil and the error // object and the error, otherwise will return nil and the error
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (_ fs.Object, err error) { func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (_ fs.Object, err error) {
fs.Debugf(f, "cp input ./%s # %+v %d", src.Remote(), options, src.Size()) return f.put(ctx, in, src, src.Remote(), options...)
}
func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, remote string, options ...fs.OpenOption) (_ fs.Object, err error) {
fs.Debugf(f, "cp input ./%s # %+v %d", remote, options, src.Size())
// Reject options we don't support. // Reject options we don't support.
for _, option := range options { for _, option := range options {
@ -539,7 +543,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
} }
} }
bucketName, bucketPath := f.absolute(src.Remote()) bucketName, bucketPath := f.absolute(remote)
upload, err := f.project.UploadObject(ctx, bucketName, bucketPath, nil) upload, err := f.project.UploadObject(ctx, bucketName, bucketPath, nil)
if err != nil { if err != nil {
@ -549,7 +553,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
if err != nil { if err != nil {
aerr := upload.Abort() aerr := upload.Abort()
if aerr != nil && !errors.Is(aerr, uplink.ErrUploadDone) { if aerr != nil && !errors.Is(aerr, uplink.ErrUploadDone) {
fs.Errorf(f, "cp input ./%s %+v: %+v", src.Remote(), options, aerr) fs.Errorf(f, "cp input ./%s %+v: %+v", remote, options, aerr)
} }
} }
}() }()
@ -574,7 +578,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
} }
err = fserrors.RetryError(err) err = fserrors.RetryError(err)
fs.Errorf(f, "cp input ./%s %+v: %+v\n", src.Remote(), options, err) fs.Errorf(f, "cp input ./%s %+v: %+v\n", remote, options, err)
return nil, err return nil, err
} }
@ -601,7 +605,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
return nil, err return nil, err
} }
return newObjectFromUplink(f, src.Remote(), upload.Info()), nil return newObjectFromUplink(f, remote, upload.Info()), nil
} }
// PutStream uploads to the remote path with the modTime given of indeterminate // PutStream uploads to the remote path with the modTime given of indeterminate

View File

@ -176,9 +176,9 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (_ io.ReadC
// But for unknown-sized objects (indicated by src.Size() == -1), Upload should either // But for unknown-sized objects (indicated by src.Size() == -1), Upload should either
// return an error or update the object properly (rather than e.g. calling panic). // return an error or update the object properly (rather than e.g. calling panic).
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) { func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) {
fs.Debugf(o, "cp input ./%s %+v", src.Remote(), options) fs.Debugf(o, "cp input ./%s %+v", o.Remote(), options)
oNew, err := o.fs.Put(ctx, in, src, options...) oNew, err := o.fs.put(ctx, in, src, o.Remote(), options...)
if err == nil { if err == nil {
*o = *(oNew.(*Object)) *o = *(oNew.(*Object))