Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
19 changes: 14 additions & 5 deletions src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ var SyscallsLibrary = {
var pos = 0;
var off = FS.llseek(stream, 0, {{{ cDefs.SEEK_CUR }}});

var idx = Math.floor(off / struct_size);

while (idx < stream.getdents.length && pos + struct_size <= count) {
var startIdx = Math.floor(off / struct_size);
var endIdx = Math.min(stream.getdents.length, startIdx + Math.floor(count/struct_size))
for (var idx = startIdx; idx < endIdx; idx++) {
var id;
var type;
var name = stream.getdents[idx];
Expand All @@ -717,7 +717,17 @@ 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 }}}) {
continue;
}
throw e;
}
id = child.id;
type = FS.isChrdev(child.mode) ? 2 : // DT_CHR, character device.
FS.isDir(child.mode) ? 4 : // DT_DIR, directory.
Expand All @@ -733,7 +743,6 @@ var SyscallsLibrary = {
{{{ makeSetValue('dirp + pos', C_STRUCTS.dirent.d_type, 'type', 'i8') }}};
stringToUTF8(name, dirp + pos + {{{ C_STRUCTS.dirent.d_name }}}, 256);
pos += struct_size;
idx += 1;
}
FS.llseek(stream, idx * struct_size, {{{ cDefs.SEEK_SET }}});
return pos;
Expand Down
10 changes: 9 additions & 1 deletion test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5757,14 +5757,22 @@ def test_fs_nodefs_nofollow(self):
self.emcc_args += ['-lnodefs.js']
self.do_runf('fs/test_nodefs_nofollow.c', 'success')

@crossplatform
@requires_node
def test_fs_nodefs_readdir(self):
# externally setup an existing folder structure: existing/a
if self.get_setting('WASMFS'):
self.set_setting('FORCE_FILESYSTEM')
if not WINDOWS and not MACOS:
# Add an entry that isn't a directory, file, or link to test that we handle
# it correctly.
os.mkfifo(os.path.join(self.working_dir, 'named_pipe'))
os.makedirs(os.path.join(self.working_dir, 'existing', 'a'))
self.emcc_args += ['-lnodefs.js']
self.do_runf('fs/test_nodefs_readdir.c', 'success')
suffix = ""
if self.get_setting('WASMFS'):
suffix = ".wasm"
self.do_run_in_out_file_test('fs/test_nodefs_readdir.c', out_suffix=suffix)

@no_windows('no symlink support on windows')
@requires_node
Expand Down