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
3 changes: 3 additions & 0 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ FS.staticInit();
return 0;
},
mayCreate(dir, name) {
if (!FS.isDir(dir.mode)) {
return {{{ cDefs.ENOTDIR }}};
}
try {
var node = FS.lookupNode(dir, name);
return {{{ cDefs.EEXIST }}};
Expand Down
17 changes: 17 additions & 0 deletions test/fs/test_enotdir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>

int main() {
{
int src_fd = open("file", O_CREAT | O_WRONLY, 0777);
close(src_fd);
}
{
int target_fd = mkdir("file/blah", 0777);
printf("target_fd: %d, errno: %d %s\n", target_fd, errno, strerror(errno));
}
}
1 change: 1 addition & 0 deletions test/fs/test_enotdir.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_fd: -1, errno: 54 Not a directory
4 changes: 4 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5832,6 +5832,10 @@ def test_fs_write(self):
def test_fs_emptyPath(self):
self.do_run_in_out_file_test('fs/test_emptyPath.c')

@also_with_noderawfs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I forget to say we should me marking these as @Crossplatform so that they run on windows.

def test_fs_enotdir(self):
self.do_run_in_out_file_test('fs/test_enotdir.c')

@also_with_noderawfs
def test_fs_append(self):
self.do_runf('fs/test_append.c', 'success')
Expand Down
6 changes: 0 additions & 6 deletions test/wasmfs/wasmfs_mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ int main() {
// Try to make a directory with a path component that is not a directory.
errno = 0;
mkdir("/dev/stdout/fake-directory", 0777);
// TODO: This may have to change when access modes are implemented, depending
// on if we check access mode before file type.
#ifdef WASMFS
assert(errno == ENOTDIR);
#else
assert(errno == EACCES);
#endif

// Try to make a directory with a path component that does not exist.
errno = 0;
Expand Down