Skip to content
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

Fix "illegal operation on a directory, realpath" on RAM Disk #229

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');
var isCore = require('./is-core');

var realpathFS = fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
function realpathFS(path, callback) {
if (typeof fs.realpath.native === 'function') {
fs.realpath.native(path, function (realpathErr, realPath) {
if (realpathErr && realpathErr.errno === -4068) {
fs.realpath(path, callback);
} else {
return callback(realpathErr, realPath);
}
});
Comment on lines +10 to +16
Copy link
Member

Choose a reason for hiding this comment

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

this means we pay a performance cost every time. is this necessary, or on a given system where it fails, will it always fail?

Copy link
Author

Choose a reason for hiding this comment

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

This code is designated for the postcss-import on RAM Disk. This means the I/O speed is significantly improved. The production build of my Angular project takes 60-120 secs with fs.realpath.native() on my 2TB Seagate FireCuda SSHD but it only takes ~60 secs on RAM Disk mounted by imDisk with fs.realpath() (where fs.realpath.native() is illegal operation). So in general, no performance costs are paid.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how that's possible - this is always calling realpath.native, and when it errors, is adding the cost of calling realpath.

(to be clear, I have no idea what imDisk is, and the last time I heard anything about RAM Disks was in the late 1990s)

Copy link
Author

Choose a reason for hiding this comment

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

imDisk is a software to create a virtual disk using RAM on Windows: https://imdisk.en.lo4d.com/windows

The cost of calling is the trade-off for I/O speed and it only adding the call on illegal operation error.

You can clone this repository using Windows on both RAM Disk created by imDisk and your HDD/SSHD/SSD https://github.com/scttcper/ngx-toastr. After the clone, run npm i && npm start. On RAM Disk, the server will fail and you will get
image

The cause is from postcss-import using this repository to resolve the imported files from node_modules in src/style.scss. So if you alter ./node_modules/resolve/lib/async.js, the error is gone.

Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned about:

  1. adding a fix without a regression test, because there's no protection from breaking it again
  2. adding a complicated fix that might slow down the majority case to service a very niche edge case

} else {
fs.realpath(path, callback);
}
}

var defaultIsFile = function isFile(file, cb) {
fs.stat(file, function (err, stat) {
Expand Down
14 changes: 13 additions & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@ var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');

var realpathFS = fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
function realpathFS(path) {
if (typeof fs.realpathSync.native === 'function') {
try {
return fs.realpathSync.native(path);
} catch (realpathErr) {
if (!realpathErr || realpathErr.errno !== -4068) {
throw realpathErr;
}
}
}

return fs.realpathSync(path);
}

var defaultIsFile = function isFile(file) {
try {
Expand Down