diff --git a/historyKeeper.js b/historyKeeper.js index fb1d4ab1f..52ae95b2c 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -836,7 +836,7 @@ module.exports.create = function (cfg) { }); // write tasks - if(tasks && metadata.expire && metadata.expire === 'number') { + if(tasks && metadata.expire && typeof(metadata.expire) === 'number') { // the fun part... // the user has said they want this pad to expire at some point tasks.write(metadata.expire, "EXPIRE", [ channelName ], function (err) { diff --git a/storage/file.js b/storage/file.js index 4c4867641..cbb45138d 100644 --- a/storage/file.js +++ b/storage/file.js @@ -505,9 +505,13 @@ var archiveChannel = function (env, channelName, cb) { nThen(function (w) { // move the channel log and abort if anything goes wrong Fse.move(currentPath, archivePath, { overwrite: true }, w(function (err) { - if (!err) { return; } - w.abort(); - cb(err); + if (err) { + // proceed to the next block to remove metadata even if there's no channel + if (err.code === 'ENOENT') { return; } + // abort and callback for other types of errors + w.abort(); + return void cb(err); + } })); }).nThen(function (w) { // archive the dedicated metadata channel @@ -623,7 +627,7 @@ var flushUnusedChannels = function (env, cb, frame) { }; /* channelBytes - calls back with the size (in bytes) of a channel and its metadata + calls back with an error or the size (in bytes) of a channel and its metadata */ var channelBytes = function (env, chanName, cb) { var channelPath = mkPath(env, chanName); @@ -647,7 +651,6 @@ var channelBytes = function (env, chanName, cb) { return void CB(err); } dataSize = stats.size; - CB(undefined, stats.size); })); }).nThen(function () { CB(void 0, channelSize + dataSize); diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index e2a0bd0a2..e5a992343 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -314,11 +314,21 @@ define([ var newPad = false; if (newContentStr === '') { newPad = true; } + var privateDat = cpNfInner.metadataMgr.getPrivateData(); + var type = privateDat.app; + // contentUpdate may be async so we need an nthen here nThen(function (waitFor) { if (!newPad) { var newContent = JSON.parse(newContentStr); - cpNfInner.metadataMgr.updateMetadata(extractMetadata(newContent)); + var metadata = extractMetadata(newContent); + if (metadata && typeof(metadata.type) !== 'undefined' && metadata.type !== type) { + var errorText = Messages.typeError; + UI.errorLoadingScreen(errorText); + waitFor.abort(); + return; + } + cpNfInner.metadataMgr.updateMetadata(metadata); newContent = normalize(newContent); contentUpdate(newContent, waitFor); } else { @@ -356,8 +366,6 @@ define([ UI.removeLoadingScreen(emitResize); - var privateDat = cpNfInner.metadataMgr.getPrivateData(); - var type = privateDat.app; if (AppConfig.textAnalyzer && textContentGetter) { AppConfig.textAnalyzer(textContentGetter, privateDat.channel); }