Skip to content

module: fix stat with long paths on windows #2013

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

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
2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Module._findPath = function(request, paths) {
// For each path
for (var i = 0, PL = paths.length; i < PL; i++) {
// Don't search further if path doesn't exist
if (paths[i] && internalModuleStat(paths[i]) < 1) continue;
if (paths[i] && internalModuleStat(path._makeLong(paths[i])) < 1) continue;
var basePath = path.resolve(paths[i], request);
var filename;

Expand Down
26 changes: 16 additions & 10 deletions test/parallel/test-require-long-path.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
'use strict';
var common = require('../common');
var fs = require('fs');
var path = require('path');
var assert = require('assert');
const common = require('../common');
const fs = require('fs');
const path = require('path');

// make a path that is more than 260 chars long.
var fileNameLen = Math.max(261 - common.tmpDir.length - 1, 1);
var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
var fullPath = path.resolve(fileName);
const dirNameLen = Math.max(260 - common.tmpDir.length, 1);
const dirName = path.join(common.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();
fs.writeFileSync(fullPath, 'module.exports = 42;');

assert.equal(require(fullPath), 42);
fs.mkdirSync(fullDirPath);
fs.writeFileSync(indexFile, 'require("./other");');
fs.writeFileSync(otherFile, '');

require(indexFile);
require(otherFile);

fs.unlinkSync(fullPath);
common.refreshTmpDir();