Files
meteor/tools/tests/tarball.js
Avital Oliver 79f7f162f1 Fix long file paths passed to files.createTarball
The fix is actually in https://github.com/npm/fstream/pull/42,
but now we also remove our explicit path length check
that used to throw an error instead of silently losing files.

This commit also adds a self-test to test the entire flow
through `files.createTarball` and `files.extractTarGz`.
2015-03-23 19:56:19 -07:00

31 lines
1.2 KiB
JavaScript

var selftest = require('../selftest.js');
var files = require('../files.js');
var expectEqual = selftest.expectEqual;
selftest.define("create and extract tarball with long paths", function () {
var STAMP = "stamp";
// Create a directory with a single file in a long subdirectory, to
// be turned into a tarball.
var tarballInputDir = files.mkdtemp("tarball-input");
var longDir = tarballInputDir;
while (longDir.length < 300) {
longDir = files.pathJoin(longDir, "subdirectory");
}
files.mkdir_p(longDir);
var inputStampedFile = files.pathJoin(longDir, "file");
files.writeFile(inputStampedFile, STAMP);
// Make the tarball
var tarballOutputDir = files.mkdtemp("tarball");
var tarballOutputFile = files.pathJoin(tarballOutputDir, "out.tar.gz");
files.createTarball(tarballInputDir, tarballOutputFile);
// Extract the tarball and verify that the single file we created is
// present with the expected contents.
var tarballExtractedDir = files.mkdtemp("tarball-extracted");
files.extractTarGz(files.readFile(tarballOutputFile), tarballExtractedDir);
var extractedStampedFile = inputStampedFile.replace(tarballInputDir, tarballExtractedDir);
expectEqual(files.readFile(extractedStampedFile, "utf-8"), STAMP);
});