storage: make listDir return paths relative to the root

this seems more natural to work with
This commit is contained in:
Girish Ramakrishnan
2025-08-16 07:43:43 +05:30
parent 19682ec21b
commit 832a25601d
5 changed files with 13 additions and 12 deletions

View File

@@ -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;