Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Feature/windows ramdisk try2 #39

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable prefer-arrow-callback */
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Author

Choose a reason for hiding this comment

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

Whoops, my auto eslint kept changing my functions into arrow functions so I added that to stop them.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm fine with arrows all over

Copy link
Owner

Choose a reason for hiding this comment

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

But not eslint ignores

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what minimum version of node you want to support but arrow functions were added a bit later.

I've resolved this in the latest commit.

Copy link
Owner

Choose a reason for hiding this comment

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

Node 4 is the lowest :)


'use strict';

const fs = require('fs');
Expand All @@ -7,7 +9,31 @@ const promisiedFsRealpath = promisify(fs.realpath);

function realpath(filepath) {
if (typeof fs.realpath.native === 'function') {
return promisify(fs.realpath.native)(filepath);
return promisify(fs.realpath.native)(filepath).catch(function(err) {
// -4068: EISDIR: illegal operation on a directory, realpath
if (err.errno !== -4068) {
/* If errno === -4068,
Probably RAM-disk on windows.
Go straight to the default js
implementation. Otherwise the
fsBinding.realpath call may cause
the node runtime to abort.
*/
const fsBinding = process.binding('fs');

if (fsBinding.realpath) {
return new Promise((resolve, reject) => {
try {
resolve(fsBinding.realpath(filepath, 'utf8'));
} catch (e) {
reject(e);
}
});
}
}

return promisiedFsRealpath(filepath);
});
}
const fsBinding = process.binding('fs');

Expand All @@ -25,17 +51,33 @@ function realpath(filepath) {
}

function realpathSync(filepath) {
if (typeof fs.realpathSync.native === 'function') {
return fs.realpathSync.native(filepath);
let fallbackToDefault = false;
try {
if (typeof fs.realpathSync.native === 'function') {
return fs.realpathSync.native(filepath);
}
} catch (err) {
// -4068: EISDIR: illegal operation on a directory, realpath
if (err.errno === -4068) {
/* Probably RAM-disk on windows.
Go straight to the default js
implementation. Otherwise the
fsBinding.realpath call may cause
the node runtime to abort.
*/
}
fallbackToDefault = true;
}

const fsBinding = process.binding('fs');
if (!fallbackToDefault) {
const fsBinding = process.binding('fs');

if (fsBinding.realpath) {
try {
return fsBinding.realpath(filepath, 'utf8');
} catch (err) {
/* Probably RAM-disk on windows. */
if (fsBinding.realpath) {
try {
return fsBinding.realpath(filepath, 'utf8');
} catch (err) {
/* Probably RAM-disk on windows. */
}
}
}

Expand Down