syncer: expose as async

This commit is contained in:
Girish Ramakrishnan
2024-07-09 23:43:16 +02:00
parent 3a21191fba
commit d6bb32aead
2 changed files with 7 additions and 13 deletions

View File

@@ -78,17 +78,16 @@ async function addFile(sourceFile, encryption, uploader, progressCallback) {
await uploader.finish();
}
function sync(backupConfig, remotePath, dataLayout, progressCallback, callback) {
async function sync(backupConfig, remotePath, dataLayout, progressCallback) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof remotePath, 'string');
assert(dataLayout instanceof DataLayout, 'dataLayout must be a DataLayout');
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
// the number here has to take into account the s3.upload partSize (which is 10MB). So 20=200MB
const concurrency = backupConfig.limits?.syncConcurrency || (backupConfig.provider === 's3' ? 20 : 10);
syncer.sync(dataLayout, async function processTask(task) {
await syncer.sync(dataLayout, async function processTask(task) {
debug('sync: processing task: %j', task);
// the empty task.path is special to signify the directory
const destPath = task.path && backupConfig.encryptedFilenames ? hush.encryptFilePath(task.path, backupConfig.encryption) : task.path;
@@ -109,11 +108,7 @@ function sync(backupConfig, remotePath, dataLayout, progressCallback, callback)
await addFile(dataLayout.toLocalPath('./' + task.path), backupConfig.encryption, uploader, progressCallback);
});
}
}, concurrency, function (error) {
if (error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, error.message));
callback();
});
}, concurrency);
}
// this is not part of 'snapshotting' because we need root access to traverse
@@ -263,8 +258,6 @@ async function upload(backupConfig, remotePath, dataLayout, progressCallback) {
assert.strictEqual(typeof dataLayout, 'object');
assert.strictEqual(typeof progressCallback, 'function');
const syncAsync = util.promisify(sync);
await saveFsMetadata(dataLayout, `${dataLayout.localRoot()}/fsmetadata.json`);
await syncAsync(backupConfig, remotePath, dataLayout, progressCallback);
await sync(backupConfig, remotePath, dataLayout, progressCallback);
}