storage: add copyDir

we changed listDir in c44863a9bb to list
a directory . this broke copy for files since a '/' is added when listing
the file.
This commit is contained in:
Girish Ramakrishnan
2025-08-25 23:45:14 +02:00
parent cdda8649fc
commit 31df40a841
7 changed files with 90 additions and 14 deletions

View File

@@ -16,6 +16,7 @@ exports = module.exports = {
download,
copy,
copyDir,
exists,
listDir,
@@ -183,10 +184,11 @@ async function listDir(config, remotePath, batchSize, marker) {
return { entries: fileStream.splice(0, batchSize), marker }; // note: splice also modifies the array
}
async function copy(config, fromPath, toPath, progressCallback) {
async function copyInternal(config, fromPath, toPath, options, progressCallback) {
assert.strictEqual(typeof config, 'object');
assert.strictEqual(typeof fromPath, 'string');
assert.strictEqual(typeof toPath, 'string');
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof progressCallback, 'function');
const fullFromPath = path.join(getRootPath(config), fromPath);
@@ -197,7 +199,8 @@ async function copy(config, fromPath, toPath, progressCallback) {
progressCallback({ message: `Copying ${fullFromPath} to ${fullToPath}` });
let cpOptions = ((config._provider !== mounts.MOUNT_TYPE_MOUNTPOINT && config._provider !== mounts.MOUNT_TYPE_CIFS) || config.preserveAttributes) ? '-a' : '-dR';
let cpOptions = ((config._provider !== mounts.MOUNT_TYPE_MOUNTPOINT && config._provider !== mounts.MOUNT_TYPE_CIFS) || config.preserveAttributes) ? '-a' : '-d';
if (options.recursive) cpOptions += 'R';
cpOptions += config.noHardlinks ? '' : 'l'; // this will hardlink backups saving space
if (config._provider === mounts.MOUNT_TYPE_SSHFS) {
@@ -215,6 +218,24 @@ async function copy(config, fromPath, toPath, 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');
return await copyInternal(config, fromPath, toPath, { recursive: false }, progressCallback);
}
async function copyDir(config, fromPath, toPath, progressCallback) {
assert.strictEqual(typeof config, 'object');
assert.strictEqual(typeof fromPath, 'string');
assert.strictEqual(typeof toPath, 'string');
assert.strictEqual(typeof progressCallback, 'function');
return await copyInternal(config, fromPath, toPath, { recursive: true }, progressCallback);
}
async function remove(config, remotePath) {
assert.strictEqual(typeof config, 'object');
assert.strictEqual(typeof remotePath, 'string');