Remove completed chunk files inline to reduce disk space usage

This commit is contained in:
Adam Jensen 2020-03-16 14:05:10 -04:00
parent 54819d8a31
commit b72a4d43d6
1 changed files with 7 additions and 3 deletions

View File

@ -396,9 +396,6 @@ func (upload s3Upload) WriteChunk(ctx context.Context, offset int64, src io.Read
go chunkProducer.produce(optimalPartSize) go chunkProducer.produce(optimalPartSize)
for file := range fileChan { for file := range fileChan {
defer os.Remove(file.Name())
defer file.Close()
stat, err := file.Stat() stat, err := file.Stat()
if err != nil { if err != nil {
return 0, err return 0, err
@ -433,6 +430,13 @@ func (upload s3Upload) WriteChunk(ctx context.Context, offset int64, src io.Read
offset += n offset += n
bytesUploaded += n bytesUploaded += n
nextPartNum += 1 nextPartNum += 1
if err := os.Remove(file.Name()); err != nil {
return bytesUploaded, err
}
if err := file.Close(); err != nil {
return bytesUploaded, err
}
} }
return bytesUploaded - incompletePartSize, chunkProducer.err return bytesUploaded - incompletePartSize, chunkProducer.err