MCPcopy
hub / github.com/scality/cloudserver / uploadPartCopy

Function uploadPartCopy

tests/sur/quota.js:244–316  ·  view source on GitHub ↗
(bucket, key, partNumber, partSize, sleepDuration, keyToCopy, callback)

Source from the content-addressed store, hash-verified

242}
243
244function uploadPartCopy(bucket, key, partNumber, partSize, sleepDuration, keyToCopy, callback) {
245 const ETags = [];
246 let uploadId = null;
247 const parts = 5;
248 const partNumbers = Array.from(Array(parts).keys());
249 const initiateMPUParams = {
250 Bucket: bucket,
251 Key: key,
252 };
253 if (!s3Config.isQuotaInflightEnabled()) {
254 mockScuba.incrementBytesForBucket(bucket, parts * partSize);
255 }
256 return async.waterfall([
257 next => s3Client.send(new CreateMultipartUploadCommand(initiateMPUParams))
258 .then(data => {
259 uploadId = data.UploadId;
260 return next();
261 })
262 .catch(next),
263 next => {
264 const uploadPartParams = {
265 Bucket: bucket,
266 Key: key,
267 PartNumber: partNumber + 1,
268 UploadId: uploadId,
269 Body: Buffer.alloc(partSize),
270 };
271 return s3Client.send(new UploadPartCommand(uploadPartParams))
272 .then(data => {
273 ETags[partNumber] = data.ETag;
274 return next();
275 })
276 .catch(next);
277 },
278 next => wait(sleepDuration, next),
279 next => {
280 const copyPartParams = {
281 Bucket: bucket,
282 CopySource: `${bucket}/${keyToCopy}`,
283 Key: `${key}-copy`,
284 PartNumber: partNumber + 1,
285 UploadId: uploadId,
286 };
287 return s3Client.send(new UploadPartCopyCommand(copyPartParams))
288 .then(data => {
289 ETags[partNumber] = data.CopyPartResult.ETag;
290 return next(null, data.CopyPartResult.ETag);
291 })
292 .catch(next);
293 },
294 next => {
295 const params = {
296 Bucket: bucket,
297 Key: key,
298 MultipartUpload: {
299 Parts: partNumbers.map(n => ({
300 ETag: ETags[n],
301 PartNumber: n + 1,

Callers 1

quota.jsFile · 0.85

Calls 4

sendMethod · 0.80
waitFunction · 0.70

Tested by

no test coverage detected