Use whilst instead of forever
this gets rid of the Error object
This commit is contained in:
@@ -115,27 +115,25 @@ function listDir(apiConfig, backupFilePath, batchSize, iteratorCallback, callbac
|
||||
query.maxResults = batchSize;
|
||||
}
|
||||
|
||||
async.forever(function listAndDownload(foreverCallback) {
|
||||
bucket.getFiles(query, function (error, files, nextQuery) {
|
||||
if (error) return foreverCallback(error);
|
||||
let done = false;
|
||||
|
||||
if (files.length === 0) return foreverCallback(new Error('Done'));
|
||||
async.whilst(() => !done, function listAndDownload(whilstCallback) {
|
||||
bucket.getFiles(query, function (error, files, nextQuery) {
|
||||
if (error) return whilstCallback(error);
|
||||
|
||||
if (files.length === 0) { done = true; return whilstCallback(); }
|
||||
|
||||
const entries = files.map(function (f) { return { fullPath: f.name }; });
|
||||
iteratorCallback(entries, function (error) {
|
||||
if (error) return foreverCallback(error);
|
||||
if (!nextQuery) return foreverCallback(new Error('Done'));
|
||||
if (error) return whilstCallback(error);
|
||||
if (!nextQuery) { done = true; return whilstCallback(); }
|
||||
|
||||
query = nextQuery;
|
||||
|
||||
foreverCallback();
|
||||
whilstCallback();
|
||||
});
|
||||
});
|
||||
}, function (error) {
|
||||
if (error.message === 'Done') return callback(null);
|
||||
|
||||
callback(error);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
function copy(apiConfig, oldFilePath, newFilePath) {
|
||||
|
||||
Reference in New Issue
Block a user