Skip to content

Commit

Permalink
Fix long file paths passed to files.createTarball
Browse files Browse the repository at this point in the history
The fix is actually in npm/fstream#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`.
  • Loading branch information
avital committed Mar 24, 2015
1 parent 91be1ea commit 79f7f16
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scripts/dev-bundle-tool-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var packageJson = {
"source-map-support": "0.2.8",
semver: "4.1.0",
request: "2.47.0",
fstream: "1.0.2",
fstream: "https://github.com/meteor/fstream/tarball/d11b9ec4a13918447c8af7559c243c190744dd1c",

This comment has been minimized.

Copy link
@avital

avital Mar 24, 2015

Author Contributor

(I looked at the changes since 1.0.2 and them seem to only contain changes to improve error handling.)

tar: "1.0.2",
kexec: "0.2.0",
"source-map": "0.1.40",
Expand Down
11 changes: 0 additions & 11 deletions tools/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,17 +738,6 @@ files.createTarGzStream = function (dirPath, options) {
return true;
}

// Error about long paths on Windows.
// As far as we know the tarball creation seems to fail silently when path
// is too long (the files don't get copied to tarball). To avoid it, we
// shout at the core developer early so she/he takes an action.
// When the tarball is created on Mac or Linux it doesn't seem to matter.
var maxPath = 260; // Longest allowed path length on Windows
if (entry.path.length > maxPath) {
throw new Error("Path too long: " + entry.path + " is " +
entry.path.length + " characters.");
}

// Refuse to create a directory that isn't listable. Tarballs
// created on Windows will have non-executable directories (since
// executable isn't a thing in Windows directory permissions), and
Expand Down
30 changes: 30 additions & 0 deletions tools/tests/tarball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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);
});

0 comments on commit 79f7f16

Please sign in to comment.