gcs: fix copy operation
copy() is part of the interface and does not include the prefix.
This commit is contained in:
+15
-3
@@ -145,7 +145,7 @@ async function listDir(config, remotePath, batchSize, marker) {
|
||||
return { entries, marker: nextQuery || null };
|
||||
}
|
||||
|
||||
async function copy(config, fullFromPath, fullToPath, progressCallback) {
|
||||
async function copyInternal(config, fullFromPath, fullToPath, progressCallback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof fullFromPath, 'string');
|
||||
assert.strictEqual(typeof fullToPath, 'string');
|
||||
@@ -157,6 +157,18 @@ async function copy(config, fullFromPath, fullToPath, progressCallback) {
|
||||
if (copyError) throw new BoxError(BoxError.EXTERNAL_ERROR, copyError.message);
|
||||
}
|
||||
|
||||
async function copy(config, fromPath, toPath, progressCallback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof fromPath, 'string');
|
||||
assert.strictEqual(typeof toPath, 'string');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
|
||||
const fullFromPath = path.join(config.prefix, fromPath);
|
||||
const fullToPath = path.join(config.prefix, toPath);
|
||||
|
||||
await copyInternal(config, fullFromPath, fullToPath, progressCallback);
|
||||
}
|
||||
|
||||
async function copyDir(config, limits, fromPath, toPath, progressCallback) {
|
||||
assert.strictEqual(typeof config, 'object');
|
||||
assert.strictEqual(typeof limits, 'object');
|
||||
@@ -170,14 +182,14 @@ async function copyDir(config, limits, fromPath, toPath, progressCallback) {
|
||||
|
||||
let marker = null;
|
||||
while (true) {
|
||||
const batch = await listDir(config, fromPath, batchSize, marker); // returns entries relative to fromPath
|
||||
const batch = await listDir(config, fromPath, batchSize, marker); // returned entries are relative to prefix
|
||||
if (batch.entries.length === 0) break;
|
||||
total += batch.entries.length;
|
||||
progressCallback({ message: `Copying ${batch.entries.length} files from ${batch.entries[0].path} to ${batch.entries[batch.entries.length-1].path}. total: ${total}` });
|
||||
await async.eachLimit(batch.entries, concurrency, async (entry) => {
|
||||
const fullFromPath = path.join(config.prefix, entry.path);
|
||||
const fullToPath = path.join(config.prefix, toPath, path.relative(fromPath, entry.path));
|
||||
await copy(config, fullFromPath, fullToPath, progressCallback);
|
||||
await copyInternal(config, fullFromPath, fullToPath, progressCallback);
|
||||
});
|
||||
if (!batch.marker) break;
|
||||
marker = batch.marker;
|
||||
|
||||
Reference in New Issue
Block a user