module: allow long paths for require on Windows

https://github.com/nodejs/io.js/pull/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: https://github.com/nodejs/io.js/issues/1990
Fixes: https://github.com/nodejs/io.js/issues/1980
Fixes: https://github.com/nodejs/io.js/issues/1849

PR-URL: https://github.com/nodejs/io.js/pull/1991/files
Reviewed-By: Bert Belder <bertbelder@gmail.com>
pull/1994/head
Michaël Zasso 2015-06-16 13:24:08 -07:00 committed by Bert Belder
parent 52a822d944
commit 671e64ac73
2 changed files with 20 additions and 3 deletions

View File

@ -67,7 +67,7 @@ function readPackage(requestPath) {
} }
var jsonPath = path.resolve(requestPath, 'package.json'); var jsonPath = path.resolve(requestPath, 'package.json');
var json = internalModuleReadFile(jsonPath); var json = internalModuleReadFile(path._makeLong(jsonPath));
if (json === undefined) { if (json === undefined) {
return false; return false;
@ -100,7 +100,7 @@ Module._realpathCache = {};
// check if the file exists and is not a directory // check if the file exists and is not a directory
function tryFile(requestPath) { function tryFile(requestPath) {
const rc = internalModuleStat(requestPath); const rc = internalModuleStat(path._makeLong(requestPath));
return rc === 0 && toRealPath(requestPath); return rc === 0 && toRealPath(requestPath);
} }
@ -146,7 +146,7 @@ Module._findPath = function(request, paths) {
var filename; var filename;
if (!trailingSlash) { if (!trailingSlash) {
const rc = internalModuleStat(basePath); const rc = internalModuleStat(path._makeLong(basePath));
if (rc === 0) { // File. if (rc === 0) { // File.
filename = toRealPath(basePath); filename = toRealPath(basePath);
} else if (rc === 1) { // Directory. } else if (rc === 1) { // Directory.

View File

@ -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 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);
common.refreshTmpDir();
fs.writeFileSync(fullPath, 'module.exports = 42;');
assert.equal(require(fullPath), 42);
fs.unlinkSync(fullPath);