Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-TUS uploads called directly with upload path #1314

Merged
merged 4 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/storage/fs/ocis/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (fs *ocisfs) Upload(ctx context.Context, ref *provider.Reference, r io.Read
return err
}
uploadID, err := fs.InitiateUpload(ctx, ref, length, nil)
if err != nil {
return err
}
if upload, err = fs.GetUpload(ctx, uploadID); err != nil {
return errors.Wrap(err, "ocisfs: error retrieving upload")
}
Expand Down Expand Up @@ -443,7 +446,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
Str("link", link).
Msg("ocisfs: child name link has wrong target id, repairing")

if err = os.Remove(childNameLink); err != nil {
if err = os.RemoveAll(childNameLink); err != nil {
return errors.Wrap(err, "ocisfs: could not remove symlink child entry")
}
}
Expand All @@ -454,7 +457,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {
}

// only delete the upload if it was successfully written to the storage
if err = os.Remove(upload.infoPath); err != nil {
if err = os.RemoveAll(upload.infoPath); err != nil {
if !os.IsNotExist(err) {
log.Err(err).Interface("info", upload.info).Msg("ocisfs: could not delete upload info")
return
Expand Down Expand Up @@ -485,12 +488,12 @@ func (fs *ocisfs) AsTerminatableUpload(upload tusd.Upload) tusd.TerminatableUplo

// Terminate terminates the upload
func (upload *fileUpload) Terminate(ctx context.Context) error {
if err := os.Remove(upload.infoPath); err != nil {
if err := os.RemoveAll(upload.infoPath); err != nil {
if !os.IsNotExist(err) {
return err
}
}
if err := os.Remove(upload.binPath); err != nil {
if err := os.RemoveAll(upload.binPath); err != nil {
if !os.IsNotExist(err) {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/storage/fs/owncloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (fs *ocfs) Upload(ctx context.Context, ref *provider.Reference, r io.ReadCl
return err
}
uploadID, err := fs.InitiateUpload(ctx, ref, length, nil)
if err != nil {
return err
}
if upload, err = fs.GetUpload(ctx, uploadID); err != nil {
return errors.Wrap(err, "ocfs: error retrieving upload")
}
Expand Down Expand Up @@ -394,7 +397,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error {
}

// only delete the upload if it was successfully written to the storage
if err := os.Remove(upload.infoPath); err != nil {
if err := os.RemoveAll(upload.infoPath); err != nil {
if !os.IsNotExist(err) {
log.Err(err).Interface("info", upload.info).Msg("ocfs: could not delete upload info")
return err
Expand Down Expand Up @@ -423,12 +426,12 @@ func (fs *ocfs) AsTerminatableUpload(upload tusd.Upload) tusd.TerminatableUpload

// Terminate terminates the upload
func (upload *fileUpload) Terminate(ctx context.Context) error {
if err := os.Remove(upload.infoPath); err != nil {
if err := os.RemoveAll(upload.infoPath); err != nil {
if !os.IsNotExist(err) {
ishank011 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
}
if err := os.Remove(upload.binPath); err != nil {
if err := os.RemoveAll(upload.binPath); err != nil {
if !os.IsNotExist(err) {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/storage/utils/localfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (fs *localfs) Upload(ctx context.Context, ref *provider.Reference, r io.Rea
return err
}
uploadID, err := fs.InitiateUpload(ctx, ref, length, nil)
if err != nil {
return err
}
if upload, err = fs.GetUpload(ctx, uploadID); err != nil {
return errors.Wrap(err, "localfs: error retrieving upload")
}
Expand Down Expand Up @@ -341,7 +344,7 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error {
}

// only delete the upload if it was successfully written to the fs
if err := os.Remove(upload.infoPath); err != nil {
if err := os.RemoveAll(upload.infoPath); err != nil {
log := appctx.GetLogger(ctx)
log.Err(err).Interface("info", upload.info).Msg("localfs: could not delete upload info")
}
Expand All @@ -363,10 +366,10 @@ func (fs *localfs) AsTerminatableUpload(upload tusd.Upload) tusd.TerminatableUpl

// Terminate terminates the upload
func (upload *fileUpload) Terminate(ctx context.Context) error {
if err := os.Remove(upload.infoPath); err != nil {
if err := os.RemoveAll(upload.infoPath); err != nil {
return err
}
if err := os.Remove(upload.binPath); err != nil {
if err := os.RemoveAll(upload.binPath); err != nil {
return err
}
return nil
Expand Down