volumes: async'ify
This commit is contained in:
@@ -23,48 +23,39 @@ const apps = require('./apps.js'),
|
||||
|
||||
const dfAsync = async.asyncify(df), dfFileAsync = async.asyncify(df.file);
|
||||
|
||||
function getVolumeDisks(appsDataDisk, callback) {
|
||||
async function getVolumeDisks(appsDataDisk) {
|
||||
assert.strictEqual(typeof appsDataDisk, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
let volumeDisks = {};
|
||||
const allVolumes = await volumes.list();
|
||||
|
||||
volumes.list(function (error, allVolumes) {
|
||||
if (error) return callback(error);
|
||||
for (const volume of allVolumes) {
|
||||
const [error, result] = await safe(df(volume.hostPath));
|
||||
volumeDisks[volume.id] = error ? appsDataDisk : result.filesystem; // ignore any errors
|
||||
}
|
||||
|
||||
async.eachSeries(allVolumes, function (volume, iteratorDone) {
|
||||
dfFileAsync(volume.hostPath, function (error, result) {
|
||||
volumeDisks[volume.id] = error ? appsDataDisk : result.filesystem; // ignore any errors
|
||||
|
||||
iteratorDone();
|
||||
});
|
||||
}, function (error) {
|
||||
callback(error, volumeDisks);
|
||||
});
|
||||
});
|
||||
return volumeDisks;
|
||||
}
|
||||
|
||||
function getAppDisks(appsDataDisk, callback) {
|
||||
async function getAppDisks(appsDataDisk) {
|
||||
assert.strictEqual(typeof appsDataDisk, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
let appDisks = {};
|
||||
|
||||
apps.getAll(function (error, allApps) {
|
||||
if (error) return callback(error);
|
||||
return new Promise((resolve, reject) => {
|
||||
apps.getAll(async function (error, allApps) {
|
||||
if (error) return reject(error);
|
||||
|
||||
async.eachSeries(allApps, function (app, iteratorDone) {
|
||||
if (!app.dataDir) {
|
||||
appDisks[app.id] = appsDataDisk;
|
||||
return iteratorDone();
|
||||
for (const app of allApps) {
|
||||
if (!app.dataDir) {
|
||||
appDisks[app.id] = appsDataDisk;
|
||||
} else {
|
||||
const [error, result] = await safe(df.file(app.dataDir));
|
||||
appDisks[app.id] = error ? appsDataDisk : result.filesystem; // ignore any errors
|
||||
}
|
||||
}
|
||||
|
||||
dfFileAsync(app.dataDir, function (error, result) {
|
||||
appDisks[app.id] = error ? appsDataDisk : result.filesystem; // ignore any errors
|
||||
iteratorDone();
|
||||
});
|
||||
}, function (error) {
|
||||
callback(error, appDisks);
|
||||
resolve(appDisks);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -98,7 +89,7 @@ function getDisks(callback) {
|
||||
dfFileAsync.bind(null, paths.APPS_DATA_DIR),
|
||||
dfFileAsync.bind(null, info.DockerRootDir),
|
||||
getBackupDisk,
|
||||
], function (error, values) {
|
||||
], async function (error, values) {
|
||||
if (error) return callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
|
||||
// filter by ext4 and then sort to make sure root disk is first
|
||||
@@ -116,17 +107,13 @@ function getDisks(callback) {
|
||||
volumes: {} // filled below
|
||||
};
|
||||
|
||||
async.series([
|
||||
getAppDisks.bind(null, disks.appsDataDisk),
|
||||
getVolumeDisks.bind(null, disks.appsDataDisk)
|
||||
], function (error, values) {
|
||||
if (error) return callback(new BoxError(BoxError.FS_ERROR, error));
|
||||
[error, disks.apps] = await safe(getAppDisks(disks.appsDataDisk));
|
||||
if (error) return callback(error);
|
||||
|
||||
disks.apps = values[0],
|
||||
disks.volumes = values[1];
|
||||
[error, disks.volumes] = await safe(getVolumeDisks(disks.appsDataDisk));
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, disks);
|
||||
});
|
||||
callback(null, disks);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user