Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #23830 from yurenju/uuid-v2.1
Browse files Browse the repository at this point in the history
Bug 1058555 - Updating preloaded apps in FOTA/OTA results in duplicate a...
  • Loading branch information
rvandermeulen committed Sep 22, 2014
2 parents 2c5f245 + 1504ca7 commit 43f0828
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions build/test/integration/distribution.test.js
Expand Up @@ -220,6 +220,21 @@ suite('Distribution mechanism', function() {
path.join(cusDir, 'power', 'carrie_power_on.png'), false);
}

function validateUuid() {
var uuidMapping = JSON.parse(fs.readFileSync(
path.join(process.cwd(), 'customization','uuid.json')
));
var webappsPath = path.join(process.cwd(), 'profile', 'webapps');

for (let appname in uuidMapping) {
assert.ok(
fs.existsSync(path.join(webappsPath, uuidMapping[appname])),
'uuid for directory name in profile/webapps should exists, app name: ' +
appname + ', uuid: ' + uuidMapping[appname]
);
}
}

function parseCustimizeImageSetting(appConfig) {
if (typeof appConfig !== 'object') {
return '';
Expand Down Expand Up @@ -335,6 +350,7 @@ suite('Distribution mechanism', function() {
validateHomescreen();
validateWallpaper();
validateVariantSettings();
validateUuid();
done();
});
});
Expand Down
32 changes: 31 additions & 1 deletion build/webapp-manifests.js
Expand Up @@ -4,6 +4,8 @@

var utils = require('./utils');

const UUID_FILENAME = 'uuid.json';

var ManifestBuilder = function() {
this.INSTALL_TIME = Date.now();
this.UPDATE_TIME = Date.now();
Expand All @@ -17,8 +19,21 @@ ManifestBuilder.prototype.setConfig = function(config) {
this.stageManifests = {};
this.manifests = {};
this.webapps = {};
this.uuidMapping = {};
this.stageDir = this.gaia.stageDir;
utils.ensureFolderExists(this.stageDir);

// set uuidMpaaing from $GAIA_DISTRIBUTION_DIR/uuid.json if exists.
try {
var uuidFile = utils.getFile(config.GAIA_DISTRIBUTION_DIR, UUID_FILENAME);
if (uuidFile.exists()) {
utils.log('webapp-manifests',
'uuid.json in GAIA_DISTRIBUTION_DIR found.');
this.uuidMapping = JSON.parse(utils.getFileContent(uuidFile));
}
} catch (e) {
// ignore exception if GAIA_DISTRIBUTION_DIR does not exist.
}
};

ManifestBuilder.prototype.genStageWebappJSON = function() {
Expand All @@ -28,6 +43,13 @@ ManifestBuilder.prototype.genStageWebappJSON = function() {
JSON.stringify(this.stageManifests, null, 2) + '\n');
};

ManifestBuilder.prototype.genUuidJSON = function() {
var uuidFile = this.stageDir.clone();
uuidFile.append(UUID_FILENAME);
utils.writeContent(uuidFile,
JSON.stringify(this.uuidMapping, null, 2) + '\n');
};

ManifestBuilder.prototype.fillExternalAppManifest = function(webapp) {
var type = webapp.appStatus;
var isPackaged = false;
Expand All @@ -43,9 +65,16 @@ ManifestBuilder.prototype.fillExternalAppManifest = function(webapp) {
// Generate the webapp folder name in the profile. Only if it's privileged
// and it has an origin in its manifest file it'll be able to specify a custom
// folder name. Otherwise, generate an UUID to use as folder name.
var webappTargetDirName = utils.generateUUID().toString();

var uuid = this.uuidMapping[webapp.sourceDirectoryName] ||
utils.generateUUID().toString();

var webappTargetDirName = uuid;
if (type === 2 && isPackaged && webapp.pckManifest.origin) {
webappTargetDirName = utils.getNewURI(webapp.pckManifest.origin).host;
} else {
// uuid is used for webapp directory name, save it for further usage
this.uuidMapping[webapp.sourceDirectoryName] = uuid;
}

var origin = isPackaged ? 'app://' + webappTargetDirName :
Expand Down Expand Up @@ -170,6 +199,7 @@ ManifestBuilder.prototype.execute = function(config) {
this.gaia.webapps.forEach(this.genManifest, this);
this.manifestErrorSummary();
this.genStageWebappJSON();
this.genUuidJSON();
};

exports.execute = function(config) {
Expand Down
4 changes: 4 additions & 0 deletions customization/uuid.json
@@ -0,0 +1,4 @@
{
"in_app_pay_test": "{0612b315-c258-8946-99ec-a8849ea367b0}",
"mochitest": "{ed6ee224-0ce0-e040-a9b6-e60036d8dd17}"
}

0 comments on commit 43f0828

Please sign in to comment.