Skip to content

Commit

Permalink
module: allow long paths for require on Windows
Browse files Browse the repository at this point in the history
nodejs#1801 introduced internal fs methods to speed up require.
The methods do not call path._makeLong like their counterpart
from the fs module. This brings back the old behaviour.

Fixes: nodejs#1990
Fixes: nodejs#1980
Fixes: nodejs#1849
  • Loading branch information
targos committed Jun 16, 2015
1 parent 96165f9 commit 3ec4337
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function readPackage(requestPath) {
}

var jsonPath = path.resolve(requestPath, 'package.json');
var json = internalModuleReadFile(jsonPath);
var json = internalModuleReadFile(path._makeLong(jsonPath));

if (json === undefined) {
return false;
Expand Down Expand Up @@ -100,7 +100,7 @@ Module._realpathCache = {};

// check if the file exists and is not a directory
function tryFile(requestPath) {
const rc = internalModuleStat(requestPath);
const rc = internalModuleStat(path._makeLong(requestPath));
return rc === 0 && toRealPath(requestPath);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ Module._findPath = function(request, paths) {
var filename;

if (!trailingSlash) {
const rc = internalModuleStat(basePath);
const rc = internalModuleStat(path._makeLong(basePath));
if (rc === 0) { // File.
filename = toRealPath(basePath);
} else if (rc === 1) { // Directory.
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-require-long-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
var common = require('../common');
var fs = require('fs');
var path = require('path');
var assert = require('assert');

// 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 fullPath = path.resolve(fileName);

common.refreshTmpDir();
fs.writeFileSync(fullPath, 'module.exports = 42;');

assert.equal(require(fullPath), 42);

fs.unlinkSync(fullPath);

0 comments on commit 3ec4337

Please sign in to comment.