diff --git a/tools/files.js b/tools/files.js index 840fd955c7..2760384767 100644 --- a/tools/files.js +++ b/tools/files.js @@ -573,7 +573,7 @@ if (! process.env.METEOR_SAVE_TMPDIRS) { // the archive should contain a single top-level directory, which will // be renamed atomically to destPath. The entire tree will be made // readonly. -files.extractTarGz = function (buffer, destPath) { +files.extractTarGz = function (buffer, destPath, options) { var parentDir = files.pathDirname(destPath); var tempDir = files.pathJoin(parentDir, '.tmp' + utils.randomToken()); files.mkdir_p(tempDir); @@ -589,7 +589,7 @@ files.extractTarGz = function (buffer, destPath) { var extractor = new tar.Extract({ path: convertToOSPath(tempDir) }) .on('entry', function (e) { - if (process.platform === "win32") { + if (process.platform === "win32" || options.forceConvert) { // On Windows, try to convert old packages that have colons in paths // by blindly replacing all of the paths. Otherwise, we can't exen // extract the tarball diff --git a/tools/tests/built-packages/has-colons.tgz b/tools/tests/built-packages/has-colons.tgz index a15458ef43..02278cafda 100644 Binary files a/tools/tests/built-packages/has-colons.tgz and b/tools/tests/built-packages/has-colons.tgz differ diff --git a/tools/tests/colon-converter-tests.js b/tools/tests/colon-converter-tests.js index 9e951bf0b7..58df80b119 100644 --- a/tools/tests/colon-converter-tests.js +++ b/tools/tests/colon-converter-tests.js @@ -93,3 +93,23 @@ if (process.platform !== "win32") { // Tests step 3: check if old packages are converted properly to have no weird // paths for Windows +selftest.define("package with colons is converted on Windows", function () { + // We have a built package tarball in the git repo + var tarballPath = files.pathJoin(files.convertToStandardPath(__dirname), + "built-packages", "has-colons.tgz"); + + // Unpack it using our tropohouse code + var tarball = files.readFile(tarballPath); + + // Force conversion of file paths with second argument + var targetDirectory = tropohouse._extractAndConvert(tarball, true); + + // Uncomment below to check results + // console.log(utils.execFileSync("find", [targetDirectory], { + // cwd: targetDirectory + // }).stdout); + + // Saved tree hash of the correct result + selftest.expectEqual(files.treeHash(targetDirectory), + "AQX/7h0fXwHT9rNQvlBTvIZAE2g8krlnkEQMc9lTuMI="); +}); diff --git a/tools/tropohouse.js b/tools/tropohouse.js index b4666d60bd..714a210aa3 100644 --- a/tools/tropohouse.js +++ b/tools/tropohouse.js @@ -38,13 +38,16 @@ exports.default = new exports.Tropohouse(defaultWarehouseDir()); /** * Extract a package tarball, and on Windows convert file paths and metadata * @param {String} packageTarball path to tarball + * @param {Boolean} forceConvert Convert paths even on unix, for testing * @return {String} Temporary directory with contents of package */ -exports._extractAndConvert = function (packageTarball) { +exports._extractAndConvert = function (packageTarball, forceConvert) { var targetDirectory = files.mkdtemp(); - files.extractTarGz(packageTarball, targetDirectory); + files.extractTarGz(packageTarball, targetDirectory, { + forceConvert: forceConvert + }); - if (process.platform === "win32") { + if (process.platform === "win32" || forceConvert) { // Packages published before the Windows release might have colons or // other unsavory characters in path names. In hopes of making most of // these packages work on Windows, we will try to automatically convert @@ -59,7 +62,6 @@ exports._extractAndConvert = function (packageTarball) { // file paths. We have already converted the colons in the actual files // while untarring. var metadata = Isopack.readMetadataFromDirectory(targetDirectory); - console.log(files.readdir(targetDirectory)); var convertedMetadata = colonConverter.convertIsopack(metadata); // Step 2. Write the isopack.json file @@ -97,6 +99,26 @@ exports._extractAndConvert = function (packageTarball) { // Result: Now we are in a state where the unibuild file paths are // consistent with the paths in the downloaded tarball. }); + + // Lastly, convert the build plugins, which are in the JSImage format + _.each(metadata.plugins, function (pluginMeta) { + var programJsonPath = files.pathJoin(targetDirectory, pluginMeta.path); + var programJson = JSON.parse(files.readFile(programJsonPath)); + + if (programJson.format !== "javascript-image-pre1") { + throw new Error("Unsupported plugin format: " + + JSON.stringify(programJson.format)); + } + + var convertedPlugin = colonConverter.convertJSImage(programJson); + + files.chmod(programJsonPath, 0777); + files.writeFile(programJsonPath, + new Buffer(JSON.stringify(convertedPlugin, null, 2), 'utf8'), + {mode: 0444}); + // Result: Now we are in a state where the build plugin file paths are + // consistent with the paths in the downloaded tarball. + }); } return targetDirectory;