Skip to content

Commit

Permalink
Fix OCM upload crush
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Oct 15, 2024
1 parent 1ae1c24 commit 1f520d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-ocm-upload-crush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix OCM upload crush

We fixed an issue where a federated instance crashed when uploading a file to a remote folder.
Fixed the cleanup blob and meta of the uploaded files.

https://github.com/cs3org/reva/pull/4884
20 changes: 12 additions & 8 deletions pkg/ocm/storage/received/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func (d *driver) Upload(ctx context.Context, req storage.UploadRequest, _ storag
return &provider.ResourceInfo{}, err
}

defer cleanup(&upload{Info: info})

client, _, rel, err := d.webdavClient(ctx, nil, &provider.Reference{
Path: filepath.Join(info.MetaData["dir"], info.MetaData["filename"]),
})
Expand Down Expand Up @@ -297,6 +299,7 @@ func (u *upload) FinishUpload(ctx context.Context) error {
}
}

defer cleanup(u)
// compare if they match the sent checksum
// TODO the tus checksum extension would do this on every chunk, but I currently don't see an easy way to pass in the requested checksum. for now we do it in FinishUpload which is also called for chunked uploads
if u.Info.MetaData["checksum"] != "" {
Expand All @@ -316,7 +319,6 @@ func (u *upload) FinishUpload(ctx context.Context) error {
err = errtypes.BadRequest("unsupported checksum algorithm: " + parts[0])
}
if err != nil {
u.cleanup()
return err
}
}
Expand All @@ -336,7 +338,6 @@ func (u *upload) FinishUpload(ctx context.Context) error {
Path: filepath.Join(u.Info.MetaData["dir"], u.Info.MetaData["filename"]),
})
if err != nil {
u.cleanup()
return err
}

Expand All @@ -358,13 +359,8 @@ func (u *upload) FinishUpload(ctx context.Context) error {
return client.WriteStream(rel, f, 0)
}

func (u *upload) cleanup() {
_ = os.Remove(u.BinPath())
_ = os.Remove(u.InfoPath())
}

func (u *upload) Terminate(ctx context.Context) error {
u.cleanup()
cleanup(u)
return nil
}

Expand Down Expand Up @@ -403,3 +399,11 @@ func (u *upload) checkHash(expected string, h hash.Hash) error {
}
return nil
}

func cleanup(u *upload) {
if u == nil {
return
}
_ = os.Remove(u.BinPath())
_ = os.Remove(u.InfoPath())
}
4 changes: 4 additions & 0 deletions pkg/rhttp/datatx/manager/tus/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
if err != nil {
appctx.GetLogger(context.Background()).Error().Err(err).Str("session", ev.Upload.ID).Msg("failed to list upload session")
} else {
if len(ups) < 1 {
appctx.GetLogger(context.Background()).Error().Str("session", ev.Upload.ID).Msg("upload session not found")
continue
}
up := ups[0]
executant := up.Executant()
ref := up.Reference()
Expand Down

0 comments on commit 1f520d1

Please sign in to comment.