storage: make listDir return paths relative to the root
this seems more natural to work with
This commit is contained in:
@@ -154,7 +154,8 @@ async function listDir(config, remotePath, batchSize, marker) {
|
||||
assert.strictEqual(typeof batchSize, 'number');
|
||||
assert(typeof marker !== 'undefined');
|
||||
|
||||
const fullRemotePath = path.join(getRootPath(config), remotePath);
|
||||
const rootPath = getRootPath(config);
|
||||
const fullRemotePath = path.join(rootPath, remotePath);
|
||||
const stack = marker ? marker.stack : [fullRemotePath];
|
||||
const fileStream = marker ? marker.fileStream : [];
|
||||
if (!marker) marker = { stack, fileStream };
|
||||
@@ -170,7 +171,7 @@ async function listDir(config, remotePath, batchSize, marker) {
|
||||
stack.push(fullEntryPath);
|
||||
} else if (dirent.isFile()) { // does not include symlink
|
||||
const stat = await fs.promises.lstat(fullEntryPath);
|
||||
fileStream.push({ path: path.relative(fullRemotePath, fullEntryPath), size: stat.size });
|
||||
fileStream.push({ path: path.relative(rootPath, fullEntryPath), size: stat.size });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -138,7 +138,7 @@ async function listDir(apiConfig, remotePath, batchSize, marker) {
|
||||
|
||||
const [files, nextQuery] = result;
|
||||
if (files.length === 0) return { entries: [], marker: null }; // no more
|
||||
const entries = files.map(function (f) { return { path: path.relative(fullRemotePath, f.name) }; });
|
||||
const entries = files.map(function (f) { return { path: path.relative(apiConfig.prefix, f.name) }; });
|
||||
return { entries, marker: nextQuery || null };
|
||||
}
|
||||
|
||||
@@ -171,8 +171,8 @@ async function copy(apiConfig, fromPath, toPath, progressCallback) {
|
||||
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(apiConfig.prefix, fromPath, entry.path);
|
||||
const fullToPath = path.join(apiConfig.prefix, toPath, entry.path);
|
||||
const fullFromPath = path.join(apiConfig.prefix, entry.path);
|
||||
const fullToPath = path.join(apiConfig.prefix, toPath, path.relative(fromPath, entry.path));
|
||||
await copyFile(apiConfig, fullFromPath, fullToPath, progressCallback);
|
||||
});
|
||||
if (!batch.marker) break;
|
||||
|
||||
@@ -101,7 +101,7 @@ async function listDir(apiConfig, dir, batchSize, marker) {
|
||||
assert(typeof marker !== 'undefined');
|
||||
|
||||
// Result: array of { path, size }
|
||||
// path is relative to the dir being listed
|
||||
// path is relative to the prefix/root and not the _dir_ being listed
|
||||
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'listDir is not implemented');
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -359,7 +359,7 @@ async function listDir(apiConfig, remotePath, batchSize, marker) {
|
||||
const [error, listData] = await safe(s3.listObjectsV2(listParams));
|
||||
if (error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Error listing objects in ${fullRemotePath}. ${formatError(error)}`);
|
||||
if (listData.KeyCount === 0 || listData.Contents.length === 0) return { entries: [], marker: null }; // no more
|
||||
const entries = listData.Contents.map(function (c) { return { path: path.relative(fullRemotePath, c.Key), size: c.Size }; });
|
||||
const entries = listData.Contents.map(function (c) { return { path: path.relative(apiConfig.prefix, c.Key), size: c.Size }; });
|
||||
return { entries, marker: !listData.IsTruncated ? null : listData.NextContinuationToken };
|
||||
}
|
||||
|
||||
@@ -487,8 +487,8 @@ async function copy(apiConfig, fromPath, toPath, progressCallback) {
|
||||
total += batch.entries.length;
|
||||
progressCallback({ message: `Copying files from ${total-batch.entries.length}-${total}` });
|
||||
await async.eachLimit(batch.entries, concurrency, async (entry) => {
|
||||
const fullFromPath = path.join(apiConfig.prefix, fromPath, entry.path);
|
||||
const fullToPath = path.join(apiConfig.prefix, toPath, entry.path);
|
||||
const fullFromPath = path.join(apiConfig.prefix, entry.path);
|
||||
const fullToPath = path.join(apiConfig.prefix, toPath, path.relative(fromPath, entry.path));
|
||||
await copyFile(apiConfig, fullFromPath, fullToPath, entry.size, progressCallback);
|
||||
});
|
||||
if (!batch.marker) break;
|
||||
|
||||
Reference in New Issue
Block a user