-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: use UNC paths when loading native addons
When using require to load a native addon the path must be converted into a long path, otherwise the addon will fail to be loaded on windows if the path is longer than 260 characters. PR-URL: #2965 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <inglor@gmail.com>
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <node.h> | ||
#include <v8.h> | ||
|
||
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) { | ||
v8::Isolate* isolate = args.GetIsolate(); | ||
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world")); | ||
} | ||
|
||
void init(v8::Local<v8::Object> target) { | ||
NODE_SET_METHOD(target, "hello", Method); | ||
} | ||
|
||
NODE_MODULE(binding, init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
// make a path that is more than 260 chars long. | ||
// Any given folder cannot have a name longer than 260 characters, | ||
// so create 10 nested folders each with 30 character long names. | ||
var addonDestinationDir = path.resolve(common.tmpDir); | ||
|
||
for (var i = 0; i < 10; i++) { | ||
addonDestinationDir = path.join(addonDestinationDir, 'x'.repeat(30)); | ||
fs.mkdirSync(addonDestinationDir); | ||
} | ||
|
||
const addonPath = path.join(__dirname, 'build', 'Release', 'binding.node'); | ||
const addonDestinationPath = path.join(addonDestinationDir, 'binding.node'); | ||
|
||
// Copy binary to long path destination | ||
var contents = fs.readFileSync(addonPath); | ||
fs.writeFileSync(addonDestinationPath, contents); | ||
|
||
// Attempt to load at long path destination | ||
var addon = require(addonDestinationPath); | ||
assert(addon != null); | ||
assert(addon.hello() == 'world'); |