wipe all packages (from this server) on resetData

note that we should NOT wipe the symlinked tool if we're running from a
release, but we haven't done that yet
This commit is contained in:
David Glasser
2014-08-05 17:59:38 -07:00
parent 85d9c89eb9
commit 332215ae7d
5 changed files with 34 additions and 6 deletions

View File

@@ -119,7 +119,8 @@ _.extend(OfficialCatalog.prototype, {
var localData = packageClient.loadCachedServerData();
var allPackageData;
if (! self.offline ) {
allPackageData = packageClient.updateServerPackageData(localData);
var updateResult = packageClient.updateServerPackageData(localData);
allPackageData = updateResult.data;
if (! allPackageData) {
// If we couldn't contact the package server, use our local data.
allPackageData = localData;
@@ -127,6 +128,9 @@ _.extend(OfficialCatalog.prototype, {
// caller and let them handle it?)
process.stderr.write("Warning: could not connect to package server\n");
}
if (updateResult.resetData) {
tropohouse.default.wipeAllPackages();
}
} else {
allPackageData = localData;
}

View File

@@ -1299,7 +1299,7 @@ main.registerCommand({
var savedData = packageClient.updateServerPackageData(null, {
packageStorageFile: tmpDataJson
});
}).data;
if (!savedData) {
// will have already printed an error
process.exit(2);

View File

@@ -188,6 +188,7 @@ exports.updateServerPackageData = function (cachedServerData, options) {
cachedServerData = cachedServerData || emptyCachedServerDataJson();
var done = false;
var ret = {resetData: false};
var conn = openPackageServerConnection();
@@ -213,7 +214,9 @@ exports.updateServerPackageData = function (cachedServerData, options) {
// OK, we can do that.
if (remoteData.resetData) {
cachedServerData.collections = null;
// XXX also get rid of any no longer existing packages
// The caller may want to take this as a cue to delete packages from the
// tropohouse.
ret.resetData = true;
}
// If there is no new data from the server, don't bother writing things to
@@ -251,7 +254,8 @@ exports.updateServerPackageData = function (cachedServerData, options) {
conn.close();
}
return cachedServerData;
ret.data = cachedServerData;
return ret;
};
// Returns a logged-in DDP connection to the package server, or null if

View File

@@ -460,7 +460,7 @@ selftest.define("update server package data unit test",
// been overwritten.
var data = packageClient.updateServerPackageData({ syncToken: {} }, {
packageStorageFile: packageStorageFile
});
}).data;
var packageNames = [];
@@ -476,7 +476,7 @@ selftest.define("update server package data unit test",
var newData = packageClient.updateServerPackageData(data, {
packageStorageFile: packageStorageFile,
useShortPages: true
});
}).data;
var newOnDiskData = packageClient.loadCachedServerData(packageStorageFile);
// Check that we didn't lose any data.

View File

@@ -60,6 +60,26 @@ _.extend(exports.Tropohouse.prototype, {
return relative ? relativePath : path.join(self.root, relativePath);
},
// Pretty extreme! We call this when we learn that something has changed on
// the server in a way that our sync protocol doesn't understand well.
wipeAllPackages: function () {
var self = this;
var packagesDir = path.join(self.root, config.getPackagesDirectoryName());
try {
var packages = fs.readdirSync(packagesDir);
} catch (e) {
// No packages at all? We're done.
if (e.code === 'ENOENT')
return;
throw e;
}
_.each(packages, function (package) {
// XXX don't be a fool, save meteor-tool (if not from checkout)
files.rm_recursive(path.join(packagesDir, package));
});
},
// Contacts the package server, downloads and extracts a tarball for a given
// buildRecord into a temporary directory, whose path is returned.
//