-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace fs.accessSync calls #955
Conversation
I've replaced the call to There also didn't appear to be an existing test that failed because of this, so I've added one in a separate commit. |
cc @mhdawson |
Is this page wrong https://nodejs.org/api/fs.html#fs_fs_fstat_fd_callback It would seem to say that fs.accessSync was added in v0.1.93 ? The doc is also not all that clear for fs.fstatSync. Would it through if the file existed by was not readable to the current user ? |
Yes, looks like the page you have linked to is incorrect, there's no Just tried removing read permissions from the exports file --
This is better than the original case, because the file pointed to is there on the filesystem but with insufficient access permissions (in the original the code fell through to the last tried candidate location which turned out to not exist). |
I think you have to check the mode field of the stat result for read permissions to reach the same result as with access. Or you could try to read at least a part of the file. |
Right unless we find a better check we'll be making it worse for versions other than 0.10.X. Can you look into how we can achieve a check which is closer to the original. |
@@ -0,0 +1,3 @@ | |||
var addon = require('bindings')('hello'); | |||
exports.hello = function() { return addon.hello() } | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you drop the blank line and add 'use strict'
at the top?
@mhdawson I would guess that the easiest solution would be to use Would that make sense? Presumably the alternative is for @richardlau to implement something that mimics the functionality of |
@bnoordhuis is there currently a test in node-gyp that builds a module? |
Updated the test commit to address comments from @bnoordhuis. I found another line that was over 80 characters so have shortened that one (via another var) as well. Also updated the fix so that it checks the mode based on the uid and gid of the file being tested to check if the file is readable based on comments from @mhdawson and @Flarna. I also decided to add extra logging to this area, including one at log level |
} catch (exception) { | ||
// this candidate was not found or not readable, do nothing | ||
log.silly(node_exp_file, 'does not exist') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this, should be using prefix like other log messages. Will fix tomorrow.
dbb775c
to
b17eea6
Compare
log.verbose(prefix, 'Found exports file: %s', node_exp_file) | ||
} else { | ||
log.error(prefix, 'Could not find exports file') | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you break out this block into a separate function?
Also, the try body should be smaller. It should basically just be the fs.statSync()
call, nothing more, else there is too much space for bugs to hide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, okay will do.
d7a5a69
to
efedde8
Compare
Extracted function as requested by @bnoordhuis. Added tests for extracted function. I've also made the code bail out with an error if it can't find a readable exports file (before it would pass the last tried candidate on to gyp even though we know it isn't readable). CC @mhdawson |
} | ||
|
||
return found | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: if the sole purpose is to find out if the file can be read from, why don't you try to open it in read-only mode? It's shorter and less error-prone, IMO.
for (var i = 0; i < candidates.length; i += 1) {
var filename = path.resolve(candidates[i])
try {
var fd = fs.openSync(filename, 'r')
} catch (e) {
continue
}
fs.closeSync(fd)
return filename
}
EDIT: That will also Just Work on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, that's much more concise. Should it still be broken out into its own function, or in-lined as it was originally with the fs.accessSync call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep it in a separate function, easier to test in isolation.
Code and tests reworked to use |
fs.accessSync does not exist in Node 0.10.x.
So with the current version of the changes, if I sabotage my AIX Node installation,
With
|
PR-URL: #955 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
fs.accessSync does not exist in Node 0.10.x. PR-URL: #955 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Thanks Richard, LGTM. Landed in c4344b3...77383dd. |
A bit late I guess but LGTM from me as well |
Headline items: * Fix for Visual Studio 2015 __pfnDliNotifyHook2 failures nodejs/node-gyp#952 * Fix for AIX using fs.statSync nodejs/node-gyp#955 * More verbose msbuild.exe missing error output https://github.com/nodejs/node-gyp/pull/930/files * Added --silent for --loglevel=silent nodejs/node-gyp#937 * Enable V8 deprecation warnings for native addons nodejs/node-gyp#920 Full changelog at https://github.com/nodejs/node-gyp/blob/master/CHANGELOG.md Credit: @rvagg PR-URL: #13199 Reviewed-By: @zkat
Headline items: * Fix for Visual Studio 2015 __pfnDliNotifyHook2 failures nodejs/node-gyp#952 * Fix for AIX using fs.statSync nodejs/node-gyp#955 * More verbose msbuild.exe missing error output https://github.com/nodejs/node-gyp/pull/930/files * Added --silent for --loglevel=silent nodejs/node-gyp#937 * Enable V8 deprecation warnings for native addons nodejs/node-gyp#920 Full changelog at https://github.com/nodejs/node-gyp/blob/master/CHANGELOG.md Credit: @rvagg PR-URL: #13200 Reviewed-By: @zkat
Headline items: * Fix for Visual Studio 2015 __pfnDliNotifyHook2 failures nodejs/node-gyp#952 * Fix for AIX using fs.statSync nodejs/node-gyp#955 * More verbose msbuild.exe missing error output https://github.com/nodejs/node-gyp/pull/930/files * Added --silent for --loglevel=silent nodejs/node-gyp#937 * Enable V8 deprecation warnings for native addons nodejs/node-gyp#920 Full changelog at https://github.com/nodejs/node-gyp/blob/master/CHANGELOG.md Credit: @rvagg PR-URL: #13199 Reviewed-By: @zkat
Headline items: * Fix for Visual Studio 2015 __pfnDliNotifyHook2 failures nodejs/node-gyp#952 * Fix for AIX using fs.statSync nodejs/node-gyp#955 * More verbose msbuild.exe missing error output https://github.com/nodejs/node-gyp/pull/930/files * Added --silent for --loglevel=silent nodejs/node-gyp#937 * Enable V8 deprecation warnings for native addons nodejs/node-gyp#920 Full changelog at https://github.com/nodejs/node-gyp/blob/master/CHANGELOG.md Credit: @rvagg PR-URL: #13199 Reviewed-By: @zkat
9bfa087 (#753) added calls to
fs.accessSync
on AIX to test if the candidate exports file exists and is readable. UnfortunatelyaccessSync
does not exist in Node 0.10.x, so the exports file is not found and results in a linking error: