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

Add nodefs readdir handling for directories that contain exotic entries #22925

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,18 @@ var SyscallsLibrary = {
type = 4; // DT_DIR
}
else {
var child = FS.lookupNode(stream.node, name);
var child;
try {
child = FS.lookupNode(stream.node, name);
} catch (e) {
// If the entry is not a directory, file, or symlink, nodefs
// lookupNode will raise EINVAL. Skip these and continue.
if (e?.errno === {{{ cDefs.EINVAL }}}) {
idx += 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

idx++

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I wonder if this while loop could be re-written into a 4 loop to avoid the duplication?

var startIdx = Math.floor(off / struct_size);
var endIdx = Math.max(stream.getdents.length, startIdx + count)
for (var idx = startIdx; idx < endIdx; idx++) {
  ...
}

continue;
}
throw e;
sbc100 marked this conversation as resolved.
Show resolved Hide resolved
}
id = child.id;
type = FS.isChrdev(child.mode) ? 2 : // DT_CHR, character device.
FS.isDir(child.mode) ? 4 : // DT_DIR, directory.
Expand Down
1 change: 1 addition & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5762,6 +5762,7 @@ def test_fs_nodefs_readdir(self):
# externally setup an existing folder structure: existing/a
if self.get_setting('WASMFS'):
self.set_setting('FORCE_FILESYSTEM')
os.mkfifo(os.path.join(self.working_dir, 'named_pipe'))
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
os.makedirs(os.path.join(self.working_dir, 'existing', 'a'))
self.emcc_args += ['-lnodefs.js']
self.do_runf('fs/test_nodefs_readdir.c', 'success')
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading