diff --git a/src/library_noderawfs.js b/src/library_noderawfs.js index 863f5ad421770..d6a112c2c34ec 100644 --- a/src/library_noderawfs.js +++ b/src/library_noderawfs.js @@ -72,7 +72,14 @@ addToLibrary({ readlink(...args) { return fs.readlinkSync(...args); }, stat(...args) { return fs.statSync(...args); }, lstat(...args) { return fs.lstatSync(...args); }, - chmod(...args) { fs.chmodSync(...args); }, + chmod(path, mode, dontFollow) { + if (dontFollow && fs.lstatSync(path).isSymbolicLink()) { + // Node (and indeed linux) does not support chmod on symlinks + // https://nodejs.org/api/fs.html#fslchmodsyncpath-mode + throw new FS.ErrnoError({{{ cDefs.EOPNOTSUPP }}}); + } + fs.chmodSync(path, mode); + }, fchmod(fd, mode) { var stream = FS.getStreamChecked(fd); fs.fchmodSync(stream.nfd, mode); diff --git a/test/common.py b/test/common.py index 1d09d1c8155f7..1805fb3d2c2c0 100644 --- a/test/common.py +++ b/test/common.py @@ -381,9 +381,7 @@ def metafunc(self, wasmfs, *args, **kwargs): if wasmfs: self.set_setting('WASMFS') self.emcc_args.append('-DWASMFS') - f(self, *args, **kwargs) - else: - f(self, *args, **kwargs) + f(self, *args, **kwargs) parameterize(metafunc, {'': (False,), 'wasmfs': (True,)}) diff --git a/test/stat/test_chmod.c b/test/stat/test_chmod.c index f7db360054975..bbb9d5ecfb824 100644 --- a/test/stat/test_chmod.c +++ b/test/stat/test_chmod.c @@ -49,7 +49,7 @@ void test() { int err; int lastctime; struct stat s; - + // // chmod a file // @@ -60,12 +60,12 @@ void test() { sleep(1); // do the actual chmod - err = chmod("file", 0200); + err = chmod("file", S_IWUSR); assert(!err); memset(&s, 0, sizeof s); stat("file", &s); - assert(s.st_mode == (0200 | S_IFREG)); + assert(s.st_mode == (S_IWUSR | S_IFREG)); assert(s.st_ctime != lastctime); // @@ -74,26 +74,25 @@ void test() { lastctime = s.st_ctime; sleep(1); - err = fchmod(open("file", O_WRONLY), 0100); + err = fchmod(open("file", O_WRONLY), S_IXUSR); assert(!err); memset(&s, 0, sizeof s); stat("file", &s); - assert(s.st_mode == (0100 | S_IFREG)); + assert(s.st_mode == (S_IXUSR | S_IFREG)); assert(s.st_ctime != lastctime); - // // fchmodat a file // lastctime = s.st_ctime; sleep(1); - err = fchmodat(AT_FDCWD, "otherfile", 0100, 0); + err = fchmodat(AT_FDCWD, "otherfile", S_IXUSR, 0); assert(!err); memset(&s, 0, sizeof s); stat("otherfile", &s); - assert(s.st_mode == (0100 | S_IFREG)); + assert(s.st_mode == (S_IXUSR | S_IFREG)); assert(s.st_ctime != lastctime); // @@ -106,23 +105,23 @@ void test() { sleep(1); // do the actual chmod - err = chmod("folder", 0300); + err = chmod("folder", S_IWUSR | S_IXUSR); assert(!err); memset(&s, 0, sizeof s); stat("folder", &s); - assert(s.st_mode == (0300 | S_IFDIR)); + assert(s.st_mode == (S_IWUSR | S_IXUSR | S_IFDIR)); assert(s.st_ctime != lastctime); #ifndef WASMFS // TODO https://github.com/emscripten-core/emscripten/issues/15948 // // chmod a symlink's target // - err = chmod("file-link", 0400); + err = chmod("file-link", S_IRUSR); assert(!err); // make sure the file it references changed stat("file-link", &s); - assert(s.st_mode == (0400 | S_IFREG)); + assert(s.st_mode == (S_IRUSR | S_IFREG)); // but the link didn't lstat("file-link", &s); @@ -131,12 +130,14 @@ void test() { // // chmod the actual symlink // - err = lchmod("file-link", 0500); - assert(!err); + err = lchmod("file-link", S_IRUSR | S_IXUSR); + // On linux lchmod is not supported so allow that here. + assert(!err || errno == ENOTSUP); + printf("lchmod -> %s\n", strerror(errno)); // make sure the file it references didn't change stat("file-link", &s); - assert(s.st_mode == (0400 | S_IFREG)); + assert(s.st_mode == (S_IRUSR | S_IFREG)); #endif // WASMFS puts("success"); diff --git a/test/test_core.py b/test/test_core.py index 1f40ea10a0c64..6d0669709462c 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5593,7 +5593,10 @@ def test_fstatat(self): self.do_runf('stat/test_fstatat.c', 'success') @also_with_wasmfs + @also_with_noderawfs def test_stat_chmod(self): + if self.get_setting('WASMFS') and self.get_setting('NODERAWFS'): + self.skipTest('test requires symlink creation which currently missing from wasmfs+noderawfs') self.do_runf('stat/test_chmod.c', 'success') @also_with_wasmfs