backup: fix listDir to return path instead of fullPath

This commit is contained in:
Girish Ramakrishnan
2025-08-02 10:24:51 +02:00
parent c935744f4c
commit 4fcaae8053
6 changed files with 25 additions and 26 deletions
+1 -1
View File
@@ -154,7 +154,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({ fullPath: path.relative(fullRemotePath, fullEntryPath), size: stat.size });
fileStream.push({ path: path.relative(fullRemotePath, fullEntryPath), size: stat.size });
}
}
+6 -6
View File
@@ -127,7 +127,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 { fullPath: path.relative(fullRemotePath, f.name) }; });
const entries = files.map(function (f) { return { path: path.relative(fullRemotePath, f.name) }; });
return { entries, marker: nextQuery || null };
}
@@ -158,10 +158,10 @@ async function copy(apiConfig, fromPath, toPath, progressCallback) {
const batch = await listDir(apiConfig, fromPath, batchSize, marker); // returns entries relative to fromPath
if (batch.entries.length === 0) break;
total += batch.entries.length;
progressCallback({ message: `Copying ${batch.entries.length} files from ${batch.entries[0].fullPath} to ${batch.entries[batch.entries.length-1].fullPath}. total: ${total}` });
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.fullPath);
const fullToPath = path.join(apiConfig.prefix, toPath, entry.fullPath);
const fullFromPath = path.join(apiConfig.prefix, fromPath, entry.path);
const fullToPath = path.join(apiConfig.prefix, toPath, entry.path);
await copyFile(apiConfig, fullFromPath, fullToPath, progressCallback);
});
if (!batch.marker) break;
@@ -193,8 +193,8 @@ async function removeDir(apiConfig, remotePathPrefix, progressCallback) {
if (batch.entries.length === 0) break;
const entries = batch.entries;
total += entries.length;
progressCallback({ message: `Removing ${entries.length} files from ${entries[0].fullPath} to ${entries[entries.length-1].fullPath}. total: ${total}` });
await async.eachLimit(entries, concurrency, async (entry) => await remove(apiConfig, entry.fullPath)); // remove will add 'prefix'
progressCallback({ message: `Removing ${entries.length} files from ${entries[0].path} to ${entries[entries.length-1].path}. total: ${total}` });
await async.eachLimit(entries, concurrency, async (entry) => await remove(apiConfig, entry.path)); // remove will add 'prefix'
if (!batch.marker) break;
marker = batch.marker;
}
+2 -2
View File
@@ -92,8 +92,8 @@ async function listDir(apiConfig, dir, batchSize, marker) {
assert.strictEqual(typeof batchSize, 'number');
assert(typeof marker !== 'undefined');
// Result: array of { fullPath, size }
// fullPath is relative to the dir being listed
// Result: array of { path, size }
// path is relative to the dir being listed
throw new BoxError(BoxError.NOT_IMPLEMENTED, 'listDir is not implemented');
}
+5 -5
View File
@@ -341,7 +341,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 { fullPath: path.relative(fullRemotePath, c.Key), size: c.Size }; });
const entries = listData.Contents.map(function (c) { return { path: path.relative(fullRemotePath, c.Key), size: c.Size }; });
return { entries, marker: !listData.IsTruncated ? null : listData.NextContinuationToken };
}
@@ -469,8 +469,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.fullPath);
const fullToPath = path.join(apiConfig.prefix, toPath, entry.fullPath);
const fullFromPath = path.join(apiConfig.prefix, fromPath, entry.path);
const fullToPath = path.join(apiConfig.prefix, toPath, entry.path);
await copyFile(apiConfig, fullFromPath, fullToPath, entry.size, progressCallback);
});
if (!batch.marker) break;
@@ -537,11 +537,11 @@ async function removeDir(apiConfig, remotePathPrefix, progressCallback) {
const deleteParams = {
Bucket: apiConfig.bucket,
Delete: {
Objects: objects.map(function (o) { return { Key: path.join(apiConfig.prefix, o.fullPath) }; })
Objects: objects.map(function (o) { return { Key: path.join(apiConfig.prefix, o.path) }; })
}
};
const fullFirstPath = path.join(apiConfig.prefix, objects[0].fullPath), fullLastPath = path.join(apiConfig.prefix, objects[objects.length-1].fullPath);
const fullFirstPath = path.join(apiConfig.prefix, objects[0].path), fullLastPath = path.join(apiConfig.prefix, objects[objects.length-1].path);
progressCallback({ message: `Removing ${objects.length} files from ${fullFirstPath} to ${fullLastPath}` });
// deleteObjects does not return error if key is not found