From 332215ae7dbba0061edbe4f6489b799673a87ca4 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 5 Aug 2014 17:59:38 -0700 Subject: [PATCH] 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 --- tools/catalog.js | 6 +++++- tools/commands.js | 2 +- tools/package-client.js | 8 ++++++-- tools/tests/package-tests.js | 4 ++-- tools/tropohouse.js | 20 ++++++++++++++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tools/catalog.js b/tools/catalog.js index bb75999aa6..eb557cd436 100644 --- a/tools/catalog.js +++ b/tools/catalog.js @@ -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; } diff --git a/tools/commands.js b/tools/commands.js index cc464bba55..d9f8b370f1 100644 --- a/tools/commands.js +++ b/tools/commands.js @@ -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); diff --git a/tools/package-client.js b/tools/package-client.js index 4abb3d26aa..aad8c3ee49 100644 --- a/tools/package-client.js +++ b/tools/package-client.js @@ -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 diff --git a/tools/tests/package-tests.js b/tools/tests/package-tests.js index 2ed3dba2f1..0a9ab24427 100644 --- a/tools/tests/package-tests.js +++ b/tools/tests/package-tests.js @@ -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. diff --git a/tools/tropohouse.js b/tools/tropohouse.js index 7460b07481..7eba73d8a7 100644 --- a/tools/tropohouse.js +++ b/tools/tropohouse.js @@ -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. //