Skip to content

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

Merged
illwieckz merged 1 commit intomasterfrom
illwieckz/macos-files
Jul 10, 2024
Merged

crnlib: correct alternate code to test if a path is a directory#64
illwieckz merged 1 commit intomasterfrom
illwieckz/macos-files

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 force-pushed the illwieckz/macos-files branch from 1961276 to ac13061 Compare July 8, 2024 02:45
@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 from ac13061 to 1d4cbb3 Compare July 8, 2024 02:51
@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 illwieckz force-pushed the illwieckz/macos-files branch from d2e90f9 to 8118010 Compare July 9, 2024 02:25
@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.

@illwieckz illwieckz force-pushed the illwieckz/macos-files branch from 8118010 to 6927e86 Compare July 9, 2024 02:36
@illwieckz illwieckz force-pushed the illwieckz/macos-files branch from 6927e86 to 62b5939 Compare July 9, 2024 16:54
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 force-pushed the illwieckz/macos-files branch from 62b5939 to 571aa58 Compare July 10, 2024 15:36
@illwieckz illwieckz merged commit a386984 into master Jul 10, 2024
@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