Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real OS tmp dir on Linux for long path tests #3925

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions test/parallel/test-fs-long-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@ var common = require('../common');
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var os = require('os');

var successes = 0;

var tmpDir = common.tmpDir;
var useOsTmpDir = false;

// use real OS tmp dir on Linux when it is readable/writable
// to avoid failing tests on ecryptfs filesystems:
// https://github.com/nodejs/node/issues/2255
if (os.type() == 'Linux') {
try {
fs.accessSync(os.tmpdir(), fs.R_OK | fs.W_OK);
useOsTmpDir = true;
tmpDir = path.join(os.tmpdir(),
'node-' + process.version + '-test-' + (Math.random() * 1e6 | 0));
fs.mkdirSync(tmpDir);
} catch (e) {
useOsTmpDir = false;
tmpDir = common.tmpDir;
}
}

// make a path that will be at least 260 chars long.
var fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1);
var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
var fileNameLen = Math.max(260 - tmpDir.length - 1, 1);
var fileName = path.join(tmpDir, new Array(fileNameLen + 1).join('x'));
var fullPath = path.resolve(fileName);

common.refreshTmpDir();
if (!useOsTmpDir) {
common.refreshTmpDir();
}

console.log({
filenameLength: fileName.length,
Expand All @@ -30,5 +52,8 @@ fs.writeFile(fullPath, 'ok', function(err) {

process.on('exit', function() {
fs.unlinkSync(fullPath);
if (useOsTmpDir) {
fs.rmdirSync(tmpDir);
}
assert.equal(2, successes);
});
37 changes: 33 additions & 4 deletions test/parallel/test-require-long-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,38 @@
const common = require('../common');
const fs = require('fs');
const path = require('path');
const os = require('os');

var tmpDir = common.tmpDir;
var useOsTmpDir = false;

// use real OS tmp dir on Linux when it is readable/writable
// to avoid failing tests on ecryptfs filesystems:
// https://github.com/nodejs/node/issues/2255
if (os.type() == 'Linux') {
try {
fs.accessSync(os.tmpdir(), fs.R_OK | fs.W_OK);
useOsTmpDir = true;
tmpDir = path.join(os.tmpdir(),
'node-' + process.version + '-test-' + (Math.random() * 1e6 | 0));
fs.mkdirSync(tmpDir);
} catch (e) {
useOsTmpDir = false;
tmpDir = common.tmpDir;
}
}

// make a path that is more than 260 chars long.
const dirNameLen = Math.max(260 - common.tmpDir.length, 1);
const dirName = path.join(common.tmpDir, 'x'.repeat(dirNameLen));
const dirNameLen = Math.max(260 - tmpDir.length, 1);
const dirName = path.join(tmpDir, 'x'.repeat(dirNameLen));
const fullDirPath = path.resolve(dirName);

const indexFile = path.join(fullDirPath, 'index.js');
const otherFile = path.join(fullDirPath, 'other.js');

common.refreshTmpDir();
if (!useOsTmpDir) {
common.refreshTmpDir();
}

fs.mkdirSync(fullDirPath);
fs.writeFileSync(indexFile, 'require("./other");');
Expand All @@ -20,4 +42,11 @@ fs.writeFileSync(otherFile, '');
require(indexFile);
require(otherFile);

common.refreshTmpDir();
if (useOsTmpDir) {
fs.unlinkSync(indexFile);
fs.unlinkSync(otherFile);
fs.rmdirSync(fullDirPath);
fs.rmdirSync(tmpDir);
} else {
common.refreshTmpDir();
}