@@ -5,6 +5,7 @@ const is = require('is-type-of');
5
5
const util = require ( 'util' ) ;
6
6
const path = require ( 'path' ) ;
7
7
const mime = require ( 'mime' ) ;
8
+ const copy = require ( 'copy-to' ) ;
8
9
9
10
const proto = exports ;
10
11
@@ -113,8 +114,15 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) {
113
114
file, fileSize, partSize, uploadId, doneParts, name,
114
115
} = checkpoint ;
115
116
117
+ const internalDoneParts = [ ] ;
118
+
119
+ if ( doneParts . length > 0 ) {
120
+ copy ( doneParts ) . to ( internalDoneParts ) ;
121
+ }
122
+
116
123
const partOffs = this . _divideParts ( fileSize , partSize ) ;
117
124
const numParts = partOffs . length ;
125
+ let multipartFinish = false ;
118
126
119
127
const uploadPartJob = function * uploadPartJob ( self , partNo ) {
120
128
if ( ! self . isCancel ( ) ) {
@@ -126,12 +134,16 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) {
126
134
} ;
127
135
128
136
const result = yield self . _uploadPart ( name , uploadId , partNo , data ) ;
129
- if ( ! self . isCancel ( ) ) {
130
- doneParts . push ( {
137
+ if ( ! self . isCancel ( ) && ! multipartFinish ) {
138
+ checkpoint . doneParts . push ( {
139
+ number : partNo ,
140
+ etag : result . res . headers . etag ,
141
+ } ) ;
142
+
143
+ internalDoneParts . push ( {
131
144
number : partNo ,
132
145
etag : result . res . headers . etag ,
133
146
} ) ;
134
- checkpoint . doneParts = doneParts ;
135
147
136
148
if ( options && options . progress ) {
137
149
yield options . progress ( doneParts . length / numParts , checkpoint , result . res ) ;
@@ -148,7 +160,7 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) {
148
160
} ;
149
161
150
162
const all = Array . from ( new Array ( numParts ) , ( x , i ) => i + 1 ) ;
151
- const done = doneParts . map ( p => p . number ) ;
163
+ const done = internalDoneParts . map ( p => p . number ) ;
152
164
const todo = all . filter ( p => done . indexOf ( p ) < 0 ) ;
153
165
const defaultParallel = 5 ;
154
166
const parallel = options . parallel || defaultParallel ;
@@ -168,7 +180,8 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) {
168
180
}
169
181
170
182
// start uploads jobs
171
- const errors = yield this . _thunkPool ( jobs , parallel ) ;
183
+ const errors = this . _thunkPool ( jobs , parallel ) ;
184
+ multipartFinish = true ;
172
185
173
186
// check errors after all jobs are completed
174
187
if ( errors && errors . length > 0 ) {
@@ -183,7 +196,7 @@ proto._resumeMultipart = function* _resumeMultipart(checkpoint, options) {
183
196
throw this . _makeCancelEvent ( ) ;
184
197
}
185
198
}
186
- return yield this . completeMultipartUpload ( name , uploadId , doneParts , options ) ;
199
+ return yield this . completeMultipartUpload ( name , uploadId , internalDoneParts , options ) ;
187
200
} ;
188
201
189
202
0 commit comments