-
Notifications
You must be signed in to change notification settings - Fork 5
fs.realpathSync.native fails when on a RAM disk on Windows #35
Comments
Oh, it aborts? 😞 Would you be able to put together a PR the prevents this? |
New PR #39 |
It's work... function realpathSync(filepath) {
if (typeof fs.realpathSync.native === 'function') {
try {
return fs.realpathSync.native(filepath);
} catch (err) {
/* Probably RAM-disk on windows. */
return fs.realpathSync(filepath);
}
}
const fsBinding = process.binding('fs');
if (fsBinding.realpath) {
try {
return fsBinding.realpath(filepath, 'utf8');
} catch (err) {
/* Probably RAM-disk on windows. */
}
}
return fs.realpathSync(filepath);
} |
on one to fix the only bug? |
Apart from using a Windows RAM disk, this optimization module breaks under Contrast Security which hides fs.realpathSync.native. Versions of Node 10 and above changed their "process binding" realpath from sync to async, so getting to line 36 throws the hard abort. Lines 27 to 42 in 7d20312
https://github.com/nodejs/node/blob/v10.0.0/src/node_file.cc#L1170 Since it's impossible to catch the abort or to find the internal method's contract, I wonder if the optimization of using the native realpath should be dropped in the sync case? I.e. delete lines 32-40. (I don't know if Node has public mechanisms to turn an async method into a sync one). |
Never mind, the latest Contrast version seems to correctly expose fs.realpathSync.native. |
I've published a v3 and deprecated it - all current releases of node supports |
I see the comment further down wrapping a different part of the realpathSync function in a try/catch for this case, but the top part also fails when in this situation.
If I change the code to this:
Then the 2nd part of the function (the one with the existing comment) makes node completely crash due to this line:
fsBinding.realpath(filepath, 'utf8');
Essentially, under this condition you'd want to skip both of the above attempts and fallback to
fs.realpathSync(filepath)
The text was updated successfully, but these errors were encountered: