-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: improve error perf of sync
lstat
+fstat
- Loading branch information
1 parent
dc1c50b
commit b32f918
Showing
5 changed files
with
47 additions
and
54 deletions.
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
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 |
---|---|---|
|
@@ -72,7 +72,6 @@ const { | |
ERR_INVALID_ARG_VALUE, | ||
}, | ||
AbortError, | ||
uvErrmapGet, | ||
uvException, | ||
} = require('internal/errors'); | ||
|
||
|
@@ -1621,19 +1620,6 @@ function statfs(path, options = { bigint: false }, callback) { | |
binding.statfs(pathModule.toNamespacedPath(path), options.bigint, req); | ||
} | ||
|
||
function hasNoEntryError(ctx) { | ||
if (ctx.errno) { | ||
const uvErr = uvErrmapGet(ctx.errno); | ||
return uvErr?.[0] === 'ENOENT'; | ||
} | ||
|
||
if (ctx.error) { | ||
return ctx.error.code === 'ENOENT'; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
Check warning on line 1623 in lib/fs.js GitHub Actions / lint-js-and-md
|
||
* Synchronously retrieves the `fs.Stats` for | ||
* the file descriptor. | ||
|
@@ -1645,9 +1631,10 @@ function hasNoEntryError(ctx) { | |
*/ | ||
function fstatSync(fd, options = { bigint: false }) { | ||
fd = getValidatedFd(fd); | ||
const ctx = { fd }; | ||
const stats = binding.fstat(fd, options.bigint, undefined, ctx); | ||
handleErrorFromBinding(ctx); | ||
const stats = binding.fstat(fd, options.bigint); | ||
if (stats === undefined) { | ||
return; | ||
} | ||
return getStatsFromBinding(stats); | ||
} | ||
|
||
|
@@ -1663,13 +1650,14 @@ function fstatSync(fd, options = { bigint: false }) { | |
*/ | ||
function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) { | ||
path = getValidatedPath(path); | ||
const ctx = { path }; | ||
const stats = binding.lstat(pathModule.toNamespacedPath(path), | ||
options.bigint, undefined, ctx); | ||
if (options.throwIfNoEntry === false && hasNoEntryError(ctx)) { | ||
return undefined; | ||
const stats = binding.lstat( | ||
pathModule.toNamespacedPath(path), | ||
options.bigint, | ||
); | ||
|
||
if (stats === undefined) { | ||
return; | ||
} | ||
handleErrorFromBinding(ctx); | ||
return getStatsFromBinding(stats); | ||
} | ||
|
||
|
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