diff --git a/src/library_nodefs.js b/src/library_nodefs.js index 5570bcc68f5c8..21e0561b783d9 100644 --- a/src/library_nodefs.js +++ b/src/library_nodefs.js @@ -138,7 +138,7 @@ addToLibrary({ } return { dev: stat.dev, - ino: stat.ino, + ino: node.id, mode: stat.mode, nlink: stat.nlink, uid: stat.uid, diff --git a/test/common.py b/test/common.py index 87111f5bd3ebf..541d89aaca73f 100644 --- a/test/common.py +++ b/test/common.py @@ -742,27 +742,16 @@ def make_executable(name): def make_dir_writeable(dirname): - # Ensure all files are readable and writable by the current user. - permission_bits = stat.S_IWRITE | stat.S_IREAD - - def is_writable(path): - return (os.stat(path).st_mode & permission_bits) != permission_bits - - def make_writable(path): - new_mode = os.stat(path).st_mode | permission_bits - os.chmod(path, new_mode) - # Some tests make files and subdirectories read-only, so rmtree/unlink will not delete # them. Force-make everything writable in the subdirectory to make it # removable and re-attempt. - if not is_writable(dirname): - make_writable(dirname) + os.chmod(dirname, 0o777) for directory, subdirs, files in os.walk(dirname): for item in files + subdirs: i = os.path.join(directory, item) if not os.path.islink(i): - make_writable(i) + os.chmod(i, 0o777) def force_delete_dir(dirname): diff --git a/test/fs/test_fs_readdir_ino_matches_stat_ino.c b/test/fs/test_fs_readdir_ino_matches_stat_ino.c new file mode 100644 index 0000000000000..68e1f1da4e55d --- /dev/null +++ b/test/fs/test_fs_readdir_ino_matches_stat_ino.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// TODO: Consider merging this with test/dirent/test_readdir.c? +// That test doesn't work on nodefs, which has to be fixed before these two +// tests can be merged . + +void setup() { + // If the node working directory does not have execute permissions, then + // `fs.readdir` will fail. For that reason we have to work in a subdirectory + // and remove execute permissions from that. + mkdir("sub", 0775); + assert(chdir("sub") == 0); + int res = open("b", O_CREAT, 0777); + assert(res >= 0); + assert(close(res) == 0); + assert(symlink("b", "a") == 0); +} + +int main() { + setup(); + int dirfd = open(".", O_RDONLY); + assert(dirfd > 0); + DIR *dirp = fdopendir(dirfd); + assert(dirp != NULL); + struct stat sta, stb; + assert(lstat("a", &sta) == 0); + assert(lstat("b", &stb) == 0); + // Test that removing permissions from the directory does not affect the + // already open directory handle that we have (dirp). +#ifndef NODERAWFS + assert(chmod(".", 0675) == 0); +#endif + int a_ino = -1; + int b_ino = -1; + struct dirent *ep; + while ((ep = readdir(dirp))) { + if (strcmp(ep->d_name, "a") == 0) { + a_ino = ep->d_ino; + } + if (strcmp(ep->d_name, "b") == 0) { + b_ino = ep->d_ino; + } + } + assert(errno == 0); + assert(a_ino >= 0); + assert(b_ino >= 0); + printf("readdir a_ino: %d, b_ino: %d\n", a_ino, b_ino); + printf("stat a_ino: %llu, b_ino: %llu\n", sta.st_ino, stb.st_ino); + assert(a_ino == sta.st_ino); + assert(b_ino == stb.st_ino); + printf("success\n"); + return 0; +} diff --git a/test/test_core.py b/test/test_core.py index 015601b228aa2..480efd9ce6476 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5858,6 +5858,10 @@ def test_fs_rename_on_existing(self): self.set_setting('FORCE_FILESYSTEM') self.do_runf('fs/test_fs_rename_on_existing.c', 'success') + @also_with_nodefs_both + def test_fs_readdir_ino_matches_stat_ino(self): + self.do_runf('fs/test_fs_readdir_ino_matches_stat_ino.c', 'success') + @also_with_nodefs_both def test_fs_open_no_permissions(self): self.do_runf('fs/test_fs_open_no_permissions.c', 'success')