Skip to content

Commit

Permalink
module: allow long paths for require on Windows
Browse files Browse the repository at this point in the history
#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: #1990
Fixes: #1980
Fixes: #1849

PR-URL: https://github.com/nodejs/io.js/pull/1991/files
Reviewed-By: Bert Belder <[email protected]>
  • Loading branch information
targos authored and piscisaureus committed Jun 16, 2015
1 parent 52a822d commit 671e64a
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 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);

1 comment on commit 671e64a

@rvagg
Copy link
Member

@rvagg rvagg commented on 671e64a Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piscisaureus FYI this came in with PR-URL: https://github.com/nodejs/io.js/pull/1991/files, i.e. copypasta of /files in the url

Please sign in to comment.