releaseFile.setRelease should be in-memory only

This will let us try several times for 'meteor update' and not write
until success.
This commit is contained in:
David Glasser
2014-11-18 16:19:03 -08:00
parent d9ff79cd9c
commit 11ab8edaa9
2 changed files with 74 additions and 20 deletions

View File

@@ -575,7 +575,9 @@ main.registerCommand({
if (buildmessage.jobHasMessages())
return;
projectContext.releaseFile.write(
// Overwrite .meteor/release. (Will not be written to disk until the end of
// prepareProjectForBuild.)
projectContext.releaseFile.setRelease(
release.current.isCheckout() ? "none" : release.current.name);
if (buildmessage.jobHasMessages())
return;
@@ -1343,8 +1345,9 @@ main.registerCommand({
projectContext.initializeCatalog();
});
// Overwrite .meteor/release.
projectContext.releaseFile.write(
// Overwrite .meteor/release. (Will not be written to disk until the end of
// prepareProjectForBuild.)
projectContext.releaseFile.setRelease(
release.current.isCheckout() ? "none" : release.current.name);
var packagesToAdd = getTestPackageNames(projectContext, options.args);

View File

@@ -368,7 +368,7 @@ _.extend(exports.ProjectContext.prototype, {
self._addAppConstraints(depsAndConstraints);
self._addLocalPackageConstraints(depsAndConstraints);
// XXX #3006 Add constraints from the release
self._addReleaseConstraints(depsAndConstraints);
// XXX #3006 Add constraints from other programs, if we reimplement that.
// XXX #3006 Add a dependency on ctl
return depsAndConstraints;
@@ -397,6 +397,19 @@ _.extend(exports.ProjectContext.prototype, {
});
},
_addReleaseConstraints: function (depsAndConstraints) {
var self = this;
_.each(self.localCatalog.getAllPackageNames(), function (packageName) {
var versionRecord = self.localCatalog.getLatestVersion(packageName);
var constraint =
utils.parseConstraint(packageName + "@=" + versionRecord.version);
// Add a constraint ("this is the only version available") but no
// dependency (we don't automatically use all local packages!)
depsAndConstraints.constraints.push(constraint);
});
},
_buildResolver: function () {
var self = this;
@@ -447,6 +460,9 @@ _.extend(exports.ProjectContext.prototype, {
_saveChangedMetadata: function () {
var self = this;
// Save any changes to .meteor/release.
self.releaseFile.writeIfModified();
// Save any changes to .meteor/packages.
self.projectConstraintsFile.writeIfModified();
@@ -905,22 +921,30 @@ exports.ReleaseFile = function (options) {
var self = this;
self.filename = path.join(options.projectDir, '.meteor', 'release');
self.watchSet = null;
// The release name actually written in the file. Null if no fill. Empty if
// the file is empty.
self.unnormalizedReleaseName = null;
// The full release name (with METEOR@ if it's missing in
// unnormalizedReleaseName).
self.fullReleaseName = null;
// FOO@bar unless FOO === "METEOR" in which case "Meteor bar".
self.displayReleaseName = null;
// Just the track.
self.releaseTrack = null;
self.releaseVersion = null;
self._reset();
self._readFile();
};
_.extend(exports.ReleaseFile.prototype, {
_reset: function () {
var self = this;
self.watchSet = null;
self._modified = false;
// The release name actually written in the file. Null if no fill. Empty
// if the file is empty.
self.unnormalizedReleaseName = null;
// The full release name (with METEOR@ if it's missing in
// unnormalizedReleaseName).
self.fullReleaseName = null;
// FOO@bar unless FOO === "METEOR" in which case "Meteor bar".
self.displayReleaseName = null;
// Just the track.
self.releaseTrack = null;
// Just the version.
self.releaseVersion = null;
},
fileMissing: function () {
var self = this;
return self.unnormalizedReleaseName === null;
@@ -939,9 +963,16 @@ _.extend(exports.ReleaseFile.prototype, {
|| self.isCheckout());
},
getReleaseCatalogRecord: function () {
var self = this;
return catalog.official.getReleaseVersion(
self.releaseTrack, self.releaseVersion);
},
_readFile: function () {
var self = this;
self._reset();
// Start a new watchSet, in case we just overwrote this.
self.watchSet = new watch.WatchSet;
var contents = watch.readAndWatchFile(self.watchSet, self.filename);
@@ -953,12 +984,17 @@ _.extend(exports.ReleaseFile.prototype, {
var lines = _.compact(_.map(files.splitBufferToLines(contents),
files.trimSpaceAndComments));
// noReleaseSpecified will be true.
if (!lines.length) {
if (! lines.length) {
self.unnormalizedReleaseName = '';
return;
}
self.unnormalizedReleaseName = lines[0];
self._setRelease(lines[0]);
},
_setRelease: function (releaseName) {
var self = this;
self.unnormalizedReleaseName = releaseName;
var parts = utils.splitReleaseName(self.unnormalizedReleaseName);
self.fullReleaseName = parts[0] + '@' + parts[1];
self.displayReleaseName = utils.displayRelease(parts[0], parts[1]);
@@ -966,9 +1002,24 @@ _.extend(exports.ReleaseFile.prototype, {
self.releaseVersion = parts[1];
},
write: function (releaseName) {
// Sets the release string (in any format that we can parse) in-memory; will
// be written by writeIfModified which is called by the saveChangedMetadata
// stage of project preparation.
setRelease: function (releaseName) {
var self = this;
files.writeFileAtomically(self.filename, releaseName + '\n');
self._setRelease(releaseName);
self._modified = true;
},
writeIfModified: function () {
var self = this;
self._modified && self._write();
},
_write: function (releaseName) {
var self = this;
files.writeFileAtomically(self.filename,
self.unnormalizedReleaseName + '\n');
self._readFile();
}
});