Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Mar 22, 2021
1 parent c0e9f3f commit 6ecbe4a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/storage/utils/decomposedfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func (fs *Decomposedfs) InitiateUpload(ctx context.Context, ref *provider.Refere

log.Debug().Interface("info", info).Interface("node", n).Interface("metadata", metadata).Msg("Decomposedfs: resolved filename")

_, err = checkQuota(ctx, fs, uint64(info.Size))
if err != nil {
return nil, err
}
//_, err = checkQuota(ctx, fs, uint64(info.Size))
//if err != nil {
// return nil, err
//}

upload, err := fs.NewUpload(ctx, info)
if err != nil {
Expand Down Expand Up @@ -422,13 +422,14 @@ 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) {

fi, err := os.Stat(upload.binPath)
if err != nil {
appctx.GetLogger(upload.ctx).Err(err).Msg("Decomposedfs: could not stat uploaded file")
return
}

_, err = checkQuota(ctx, upload.fs, uint64(fi.Size()))
_, err = checkQuota(upload.ctx, upload.fs, uint64(fi.Size()))
if err != nil {
return err
}
Expand Down Expand Up @@ -699,9 +700,14 @@ func (upload *fileUpload) ConcatUploads(ctx context.Context, uploads []tusd.Uplo
func checkQuota(ctx context.Context, fs *Decomposedfs, fileSize uint64) (quotaSufficient bool, err error) {
total, inUse, err := fs.GetQuota(ctx)
if err != nil {
return false, err
switch err.(type) {
case errtypes.NotFound:
return true, nil
default:
return false, err
}
}
if fileSize > total-inUse {
if !(total == 0) && fileSize > total-inUse {
return false, errtypes.InsufficientStorage("quota exceeded")
}
return true, nil
Expand Down

0 comments on commit 6ecbe4a

Please sign in to comment.