From 671e64ac732532892e543c0a8d6efd0b8639e757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 16 Jun 2015 13:24:08 -0700 Subject: [PATCH] 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 --- lib/module.js | 6 +++--- test/parallel/test-require-long-path.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-require-long-path.js diff --git a/lib/module.js b/lib/module.js index 844b683940c2a4..31f2063231dedc 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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; @@ -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); } @@ -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. diff --git a/test/parallel/test-require-long-path.js b/test/parallel/test-require-long-path.js new file mode 100644 index 00000000000000..a69503f8d2f3df --- /dev/null +++ b/test/parallel/test-require-long-path.js @@ -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);