Incomplete sandbox content updates are now removed and reperformed

This commit is contained in:
seefo 2017-06-14 14:45:25 -07:00
parent 15a5464bab
commit 9fa21fc79f

View file

@ -101,6 +101,10 @@ function getApplicationDataDirectory() {
return path.join(getRootHifiDataDirectory(), '/Server Console');
}
// Update lock filepath
const UPDATER_LOCK_FILENAME = ".updating";
const UPDATER_LOCK_FULL_PATH = getRootHifiDataDirectory() + "/" + UPDATER_LOCK_FILENAME;
// Configure log
global.log = require('electron-log');
const logFile = getApplicationDataDirectory() + '/log.txt';
@ -630,11 +634,22 @@ function checkNewContent() {
userConfig.save(configPath);
}
});
} else if (fs.existsSync(UPDATER_LOCK_FULL_PATH)) {
backupResourceDirectoriesAndRestart();
}
}
});
}
function removeIncompleteUpdate(acResourceDirectory, dsResourceDirectory) {
if (fs.existsSync(UPDATER_LOCK_FULL_PATH)) {
log.debug('Removing incomplete content update files before copying new update');
fs.emptyDirSync(dsResourceDirectory);
fs.emptyDirSync(acResourceDirectory);
} else {
fs.ensureFileSync(UPDATER_LOCK_FULL_PATH);
}
}
function maybeInstallDefaultContentSet(onComplete) {
// Check for existing data
@ -673,7 +688,11 @@ function maybeInstallDefaultContentSet(onComplete) {
}
log.debug("Found contentPath:" + argv.contentPath);
if (argv.contentPath) {
// check if we're updating a data folder whose update is incomplete
removeIncompleteUpdate(acResourceDirectory, dsResourceDirectory);
fs.copy(argv.contentPath, getRootHifiDataDirectory(), function (err) {
if (err) {
log.debug('Could not copy home content: ' + err);
@ -682,12 +701,12 @@ function maybeInstallDefaultContentSet(onComplete) {
log.debug('Copied home content over to: ' + getRootHifiDataDirectory());
userConfig.set('homeContentLastModified', new Date());
userConfig.save(configPath);
fs.removeSync(UPDATER_LOCK_FULL_PATH);
onComplete();
});
return;
}
// Show popup
var window = new BrowserWindow({
icon: appIcon,
@ -718,6 +737,9 @@ function maybeInstallDefaultContentSet(onComplete) {
var aborted = false;
// check if we're updating a data folder whose update is incomplete
removeIncompleteUpdate(acResourceDirectory, dsResourceDirectory);
// Start downloading content set
var req = progress(request.get({
url: HOME_CONTENT_URL
@ -763,6 +785,7 @@ function maybeInstallDefaultContentSet(onComplete) {
log.debug("Finished unarchiving home content set");
userConfig.set('homeContentLastModified', new Date());
userConfig.save(configPath);
fs.removeSync(UPDATER_LOCK_FULL_PATH);
sendStateUpdate('complete');
});