volumes: async'ify
This commit is contained in:
@@ -49,7 +49,6 @@ const apps = require('./apps.js'),
|
||||
shell = require('./shell.js'),
|
||||
safe = require('safetydance'),
|
||||
system = require('./system.js'),
|
||||
util = require('util'),
|
||||
volumes = require('./volumes.js'),
|
||||
_ = require('underscore');
|
||||
|
||||
@@ -194,33 +193,30 @@ function downloadImage(manifest, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getVolumeMounts(app, callback) {
|
||||
async function getVolumeMounts(app) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
let mounts = [];
|
||||
|
||||
if (app.mounts.length === 0) return callback(null, []);
|
||||
if (app.mounts.length === 0) return [];
|
||||
|
||||
volumes.list(function (error, result) {
|
||||
if (error) return callback(error);
|
||||
const result = await volumes.list();
|
||||
|
||||
let volumesById = {};
|
||||
result.forEach(r => volumesById[r.id] = r);
|
||||
let volumesById = {};
|
||||
result.forEach(r => volumesById[r.id] = r);
|
||||
|
||||
for (const mount of app.mounts) {
|
||||
const volume = volumesById[mount.volumeId];
|
||||
for (const mount of app.mounts) {
|
||||
const volume = volumesById[mount.volumeId];
|
||||
|
||||
mounts.push({
|
||||
Source: volume.hostPath,
|
||||
Target: `/media/${volume.name}`,
|
||||
Type: 'bind',
|
||||
ReadOnly: mount.readOnly
|
||||
});
|
||||
}
|
||||
mounts.push({
|
||||
Source: volume.hostPath,
|
||||
Target: `/media/${volume.name}`,
|
||||
Type: 'bind',
|
||||
ReadOnly: mount.readOnly
|
||||
});
|
||||
}
|
||||
|
||||
callback(null, mounts);
|
||||
});
|
||||
return mounts;
|
||||
}
|
||||
|
||||
function getAddonMounts(app, callback) {
|
||||
@@ -273,18 +269,17 @@ function getAddonMounts(app, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMounts(app, callback) {
|
||||
async function getMounts(app, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
getVolumeMounts(app, function (error, volumeMounts) {
|
||||
const [error, volumeMounts] = await safe(getVolumeMounts());
|
||||
if (error) return callback(error);
|
||||
|
||||
getAddonMounts(app, function (error, addonMounts) {
|
||||
if (error) return callback(error);
|
||||
|
||||
getAddonMounts(app, function (error, addonMounts) {
|
||||
if (error) return callback(error);
|
||||
|
||||
callback(null, volumeMounts.concat(addonMounts));
|
||||
});
|
||||
callback(null, volumeMounts.concat(addonMounts));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user