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

crnlib: correct alternate code to test if a path is a directory #64

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Jul 8, 2024

The alternate code was testing for the file name in the current directory.

Fixes #63:

The alternate code was testing for the file name in the current directory.
@illwieckz illwieckz changed the title crnlib: additional way to test if a file is a directory crnlib: additional way to test if a path is a directory Jul 8, 2024
@illwieckz illwieckz force-pushed the illwieckz/macos-files branch 2 times, most recently from ea9ba2b to d2e90f9 Compare July 9, 2024 01:40
@illwieckz illwieckz changed the title crnlib: additional way to test if a path is a directory crnlib: correct alternate code to test if a path is a directory Jul 9, 2024
@illwieckz
Copy link
Member Author

One may open the folder with open then use fstatat on the file name to avoid concatenating a string, but we better assume doing an extra IO is slower than string concatenation.

@illwieckz
Copy link
Member Author

Also an alternate code to use open on the parent dir to then use fdopendir instead of opendir to then reuse the fd with fstatat is not possible as the man page says:

After a successful call to fdopendir(), fd is used internally by the implemen‐
tation, and should not otherwise be used by the application.

So this may be the fastest code.

crnlib/crn_find_files.cpp Outdated Show resolved Hide resolved
Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

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

LGTM

bool is_file = 0;
bool is_directory = false;
bool is_file = false;
bool guessed = false;
Copy link
Member

Choose a reason for hiding this comment

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

I would call it known. The word "guess" implies you are making the answer and don't know it it's correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK Done.

@illwieckz illwieckz merged commit a386984 into master Jul 10, 2024
14 checks passed
@illwieckz illwieckz deleted the illwieckz/macos-files branch July 10, 2024 15:47
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.

macOS fails to detect if a path is a file or a directory on NFS if the file is not in current directory
2 participants