Skip to content
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

Ensure the ino we give to readdir matches the ino we give to stat #23139

Merged
merged 19 commits into from
Dec 19, 2024

Conversation

hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Dec 12, 2024

If we stat a file in the nodefs it gives a different value for the inode than if we use readdir. Readdir gives the inode in the host file system, stat gives the inode in the native file system. Ideally they should agree about what the inode is.

test/test_core.py Outdated Show resolved Hide resolved
src/library_syscall.js Outdated Show resolved Hide resolved
Fix problem with directory permissions
@hoodmane
Copy link
Collaborator Author

Okay I updated this again, but now it conflicts with #23058, like several other changes I want to make. So ideally we should merge that one first and then I can update this PR to reflect those changes.

sbc100 pushed a commit that referenced this pull request Dec 14, 2024
This rule was lost in the recent switch from flake8.

This change brings back that rule which is currently in preview in ruff.

See #23139 (comment)
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

I wonder if we can make this test part of an existing readdir test that than being its own one? Maybe not.. but just a thought.

LGTM % comments

@hoodmane
Copy link
Collaborator Author

Maybe test/dirent/test_readdir.c.

@hoodmane
Copy link
Collaborator Author

test/dirent/test_readdir.c does not work in nodefs so I'd prefer to keep this test separate. Though perhaps someone should investigate why that test fails in nodefs.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 18, 2024

test/dirent/test_readdir.c does not work in nodefs so I'd prefer to keep this test separate. Though perhaps someone should investigate why that test fails in nodefs.

Yes we should fix that. Perhaps add a comment to this new test that it should be merges one day if possible.

@hoodmane
Copy link
Collaborator Author

Okay I think I addressed all the comments here.

hedwigz pushed a commit to hedwigz/emscripten that referenced this pull request Dec 18, 2024
This rule was lost in the recent switch from flake8.

This change brings back that rule which is currently in preview in ruff.

See emscripten-core#23139 (comment)
@hoodmane
Copy link
Collaborator Author

It seems that if the node working directory does not have execute permissions, this makes fs.readdir() fail. So I think I need to put back in the subdirectory.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 18, 2024

It seems that if the node working directory does not have execute permissions, this makes fs.readdir() fail. So I think I need to put back in the subdirectory.

IIRC that is exactly what the execute bit on a directory means: "can this directory be listed"

void setup() {
// If the node working directory does not have execute permissions, then
// `fs.readdir` will fail. For that reason we have to work in a subdirectory
// and remove execute permissions from that.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand.. fs.readdir should fail on any directory that doesn't have the execute bit set, regardless of weather that is CWD or a sub directory, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose I can drop the chmod, but cding into a subdirectory does fix the test, at least when I run it locally. I don't really have a clear theory as to why since it seems a bit illogical.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yes, I misremembered. The x bit is about traversing the heirachy, not list-ability. You can list directory than don't have the x bit set. That is what the r bit is for.

@hoodmane hoodmane merged commit aead0b0 into emscripten-core:main Dec 19, 2024
28 of 29 checks passed
@hoodmane hoodmane deleted the readdir_ino_matches_stat_ino branch December 19, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants