Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)})
Expand Down
31 changes: 16 additions & 15 deletions test/stat/test_chmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void test() {
int err;
int lastctime;
struct stat s;

//
// chmod a file
//
Expand All @@ -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);

//
Expand All @@ -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);

//
Expand All @@ -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);
Expand All @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down