Skip to content

Commit 6becbf1

Browse files
committed
Add nodefs handling for directories that contain exotic entries
1 parent ffeb761 commit 6becbf1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/library_syscall.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,18 @@ var SyscallsLibrary = {
717717
type = 4; // DT_DIR
718718
}
719719
else {
720-
var child = FS.lookupNode(stream.node, name);
720+
var child;
721+
try {
722+
child = FS.lookupNode(stream.node, name);
723+
} catch (e) {
724+
// If the entry is not a directory, file, or symlink, nodefs
725+
// lookupNode will raise EINVAL. Skip these and continue.
726+
if (e?.errno === {{{ cDefs.EINVAL }}}) {
727+
idx += 1;
728+
continue;
729+
}
730+
throw e;
731+
}
721732
id = child.id;
722733
type = FS.isChrdev(child.mode) ? 2 : // DT_CHR, character device.
723734
FS.isDir(child.mode) ? 4 : // DT_DIR, directory.

test/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5762,6 +5762,7 @@ def test_fs_nodefs_readdir(self):
57625762
# externally setup an existing folder structure: existing/a
57635763
if self.get_setting('WASMFS'):
57645764
self.set_setting('FORCE_FILESYSTEM')
5765+
os.mkfifo(os.path.join(self.working_dir, 'named_pipe'))
57655766
os.makedirs(os.path.join(self.working_dir, 'existing', 'a'))
57665767
self.emcc_args += ['-lnodefs.js']
57675768
self.do_runf('fs/test_nodefs_readdir.c', 'success')

0 commit comments

Comments
 (0)