Skip to content

Commit 48b6742

Browse files
authored
Run test_chmod under NODERAWFS. NFC (#23004)
1 parent 864dc2c commit 48b6742

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

src/library_noderawfs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ addToLibrary({
7272
readlink(...args) { return fs.readlinkSync(...args); },
7373
stat(...args) { return fs.statSync(...args); },
7474
lstat(...args) { return fs.lstatSync(...args); },
75-
chmod(...args) { fs.chmodSync(...args); },
75+
chmod(path, mode, dontFollow) {
76+
if (dontFollow && fs.lstatSync(path).isSymbolicLink()) {
77+
// Node (and indeed linux) does not support chmod on symlinks
78+
// https://nodejs.org/api/fs.html#fslchmodsyncpath-mode
79+
throw new FS.ErrnoError({{{ cDefs.EOPNOTSUPP }}});
80+
}
81+
fs.chmodSync(path, mode);
82+
},
7683
fchmod(fd, mode) {
7784
var stream = FS.getStreamChecked(fd);
7885
fs.fchmodSync(stream.nfd, mode);

test/common.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ def metafunc(self, wasmfs, *args, **kwargs):
381381
if wasmfs:
382382
self.set_setting('WASMFS')
383383
self.emcc_args.append('-DWASMFS')
384-
f(self, *args, **kwargs)
385-
else:
386-
f(self, *args, **kwargs)
384+
f(self, *args, **kwargs)
387385

388386
parameterize(metafunc, {'': (False,),
389387
'wasmfs': (True,)})

test/stat/test_chmod.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void test() {
4949
int err;
5050
int lastctime;
5151
struct stat s;
52-
52+
5353
//
5454
// chmod a file
5555
//
@@ -60,12 +60,12 @@ void test() {
6060
sleep(1);
6161

6262
// do the actual chmod
63-
err = chmod("file", 0200);
63+
err = chmod("file", S_IWUSR);
6464
assert(!err);
6565

6666
memset(&s, 0, sizeof s);
6767
stat("file", &s);
68-
assert(s.st_mode == (0200 | S_IFREG));
68+
assert(s.st_mode == (S_IWUSR | S_IFREG));
6969
assert(s.st_ctime != lastctime);
7070

7171
//
@@ -74,26 +74,25 @@ void test() {
7474
lastctime = s.st_ctime;
7575
sleep(1);
7676

77-
err = fchmod(open("file", O_WRONLY), 0100);
77+
err = fchmod(open("file", O_WRONLY), S_IXUSR);
7878
assert(!err);
7979

8080
memset(&s, 0, sizeof s);
8181
stat("file", &s);
82-
assert(s.st_mode == (0100 | S_IFREG));
82+
assert(s.st_mode == (S_IXUSR | S_IFREG));
8383
assert(s.st_ctime != lastctime);
8484

85-
8685
//
8786
// fchmodat a file
8887
//
8988
lastctime = s.st_ctime;
9089
sleep(1);
91-
err = fchmodat(AT_FDCWD, "otherfile", 0100, 0);
90+
err = fchmodat(AT_FDCWD, "otherfile", S_IXUSR, 0);
9291
assert(!err);
9392

9493
memset(&s, 0, sizeof s);
9594
stat("otherfile", &s);
96-
assert(s.st_mode == (0100 | S_IFREG));
95+
assert(s.st_mode == (S_IXUSR | S_IFREG));
9796
assert(s.st_ctime != lastctime);
9897

9998
//
@@ -106,23 +105,23 @@ void test() {
106105
sleep(1);
107106

108107
// do the actual chmod
109-
err = chmod("folder", 0300);
108+
err = chmod("folder", S_IWUSR | S_IXUSR);
110109
assert(!err);
111110
memset(&s, 0, sizeof s);
112111
stat("folder", &s);
113-
assert(s.st_mode == (0300 | S_IFDIR));
112+
assert(s.st_mode == (S_IWUSR | S_IXUSR | S_IFDIR));
114113
assert(s.st_ctime != lastctime);
115114

116115
#ifndef WASMFS // TODO https://github.com/emscripten-core/emscripten/issues/15948
117116
//
118117
// chmod a symlink's target
119118
//
120-
err = chmod("file-link", 0400);
119+
err = chmod("file-link", S_IRUSR);
121120
assert(!err);
122121

123122
// make sure the file it references changed
124123
stat("file-link", &s);
125-
assert(s.st_mode == (0400 | S_IFREG));
124+
assert(s.st_mode == (S_IRUSR | S_IFREG));
126125

127126
// but the link didn't
128127
lstat("file-link", &s);
@@ -131,12 +130,14 @@ void test() {
131130
//
132131
// chmod the actual symlink
133132
//
134-
err = lchmod("file-link", 0500);
135-
assert(!err);
133+
err = lchmod("file-link", S_IRUSR | S_IXUSR);
134+
// On linux lchmod is not supported so allow that here.
135+
assert(!err || errno == ENOTSUP);
136+
printf("lchmod -> %s\n", strerror(errno));
136137

137138
// make sure the file it references didn't change
138139
stat("file-link", &s);
139-
assert(s.st_mode == (0400 | S_IFREG));
140+
assert(s.st_mode == (S_IRUSR | S_IFREG));
140141
#endif // WASMFS
141142

142143
puts("success");

test/test_core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5593,7 +5593,10 @@ def test_fstatat(self):
55935593
self.do_runf('stat/test_fstatat.c', 'success')
55945594

55955595
@also_with_wasmfs
5596+
@also_with_noderawfs
55965597
def test_stat_chmod(self):
5598+
if self.get_setting('WASMFS') and self.get_setting('NODERAWFS'):
5599+
self.skipTest('test requires symlink creation which currently missing from wasmfs+noderawfs')
55975600
self.do_runf('stat/test_chmod.c', 'success')
55985601

55995602
@also_with_wasmfs

0 commit comments

Comments
 (0)