Skip to content

Trying to create a directory in a file should return ENOTDIR not EPERM #23025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

2-space indentation.

}
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 @@ -5822,6 +5822,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