use a big try-catch for migration block

This commit is contained in:
Stephen Birarda 2016-01-20 15:25:58 -08:00
parent 6ec55dc746
commit d08a64a4d6

View file

@ -338,11 +338,17 @@ function promptToMigrateContent() {
}, function(index) { }, function(index) {
if (index == 0) { if (index == 0) {
if (homeServer.state != ProcessGroupStates.STOPPED) { if (homeServer.state != ProcessGroupStates.STOPPED) {
homeServer.once('state-update', function(processGroup) { var stopThenMigrateCallback = function(processGroup) {
if (processGroup.state == ProcessGroupStates.STOPPED) { if (isShuttingDown) {
homeServer.removeListener('state-update', stopThenMigrateCallback);
} else if (processGroup.state == ProcessGroupStates.STOPPED) {
performContentMigration(); performContentMigration();
homeServer.removeListener('state-update', stopThenMigrateCallback);
} }
}); };
homeServer.on('state-update', stopThenMigrateCallback);
homeServer.stop(); homeServer.stop();
@ -397,34 +403,33 @@ function performContentMigration() {
var newModelsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'entities/models.json.gz') var newModelsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'entities/models.json.gz')
console.log("Copying Stack Manager entity file from " + modelsPath + " to " + newModelsPath); console.log("Copying Stack Manager entity file from " + modelsPath + " to " + newModelsPath);
fs.copy(modelsPath, newModelsPath, function(error){ var entitiesCopied = false;
if (!error) {
// check if there are any assets to copy
var oldAssetsPath = path.resolve(stackManagerBasePath(), 'assets');
fs.readdir(oldAssetsPath, function(error, data){ try {
if (error) { fs.copySync(modelsPath, newModelsPath);
showMigrationCompletionDialog(error);
} else if (data.length > 0) {
// assume this means the directory is not empty // check if there are any assets to copy
// and that we should copy it var oldAssetsPath = path.resolve(stackManagerBasePath(), 'assets');
var newAssetsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'assets');
console.log("Copying Stack Manager assets from " + oldAssetsPath + " to " + newAssetsPath); var assets = fs.readdirSync(oldAssetsPath);
// attempt to copy the assets folder, show correct dialog depending on success/failure if (assets.length > 0) {
fs.copy(oldAssetsPath, newAssetsPath, { // assume this means the directory is not empty
preserveTimestamps: true // and that we should copy it
}, showMigrationCompletionDialog); var newAssetsPath = path.resolve(getAssignmentClientResourcesDirectory(), 'assets');
} else {
showMigrationCompletionDialog(null); console.log("Copying Stack Manager assets from " + oldAssetsPath + " to " + newAssetsPath);
}
// attempt to copy the assets folder, show correct dialog depending on success/failure
fs.copySync(oldAssetsPath, newAssetsPath, {
preserveTimestamps: true
}); });
} else {
showMigrationCompletionDialog(error);
} }
});
showMigrationCompletionDialog(null);
} catch (error) {
showMigrationCompletionDialog(error);
}
homeServer.start(); homeServer.start();
} }