Skip to content

Commit

Permalink
fix finish upload
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Mar 22, 2021
1 parent 6ecbe4a commit c828298
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/rhttp/datatx/manager/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
w.WriteHeader(http.StatusForbidden)
case errtypes.InvalidCredentials:
w.WriteHeader(http.StatusUnauthorized)
case errtypes.InsufficientStorage:
w.WriteHeader(http.StatusInsufficientStorage)
default:
sublog.Error().Err(v).Msg("error uploading file")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ func (upload *fileUpload) writeInfo() error {
// FinishUpload finishes an upload and moves the file to the internal destination
func (upload *fileUpload) FinishUpload(ctx context.Context) (err error) {

// ensure cleanup
defer upload.discardChunk()

fi, err := os.Stat(upload.binPath)
if err != nil {
appctx.GetLogger(upload.ctx).Err(err).Msg("Decomposedfs: could not stat uploaded file")
Expand Down Expand Up @@ -621,6 +624,12 @@ func (upload *fileUpload) discardChunk() {
return
}
}
if err := os.Remove(upload.infoPath); err != nil {
if !os.IsNotExist(err) {
appctx.GetLogger(upload.ctx).Err(err).Interface("info", upload.info).Str("infoPath", upload.infoPath).Interface("info", upload.info).Msg("Decomposedfs: could not discard chunk info")
return
}
}
}

// To implement the termination extension as specified in https://tus.io/protocols/resumable-upload.html#termination
Expand Down

0 comments on commit c828298

Please sign in to comment.