Skip to content

Commit 714eaea

Browse files
authored
[FS] lookupPath should throw an error on an empty string (#23366)
It's inconsistent that lookupPath returns `node:null` when the path is an empty string. Normally it either raises `ENOENT` or `node` is truthy. This makes empty string into an edge case that every caller has to handle. `stat` has special handling for the empty string case and correctly returns ENOENT on empty string, but chmod, truncate, and mknod all crash. utime and some other functions mishandle the empty string in an unrelated way.
1 parent 5ac384b commit 714eaea

25 files changed

+44
-22
lines changed

src/library_fs.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ FS.staticInit();
172172
// paths
173173
//
174174
lookupPath(path, opts = {}) {
175-
if (!path) return { path: '', node: null };
175+
if (!path) {
176+
throw new FS.ErrnoError({{{ cDefs.ENOENT }}});
177+
}
176178
opts.follow_mount ??= true
177179

178180
if (!PATH.isAbs(path)) {
@@ -952,9 +954,6 @@ FS.staticInit();
952954
stat(path, dontFollow) {
953955
var lookup = FS.lookupPath(path, { follow: !dontFollow });
954956
var node = lookup.node;
955-
if (!node) {
956-
throw new FS.ErrnoError({{{ cDefs.ENOENT }}});
957-
}
958957
var getattr = FS.checkOpExists(node.node_ops.getattr, {{{ cDefs.EPERM }}});
959958
return getattr(node);
960959
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8350
1+
8343
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20283
1+
20273
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8332
1+
8327
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20251
1+
20241
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9349
1+
9343
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24051
1+
24041
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8298
1+
8294
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20176
1+
20166
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8298
1+
8294

0 commit comments

Comments
 (0)