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

fix/macos path handling #169

Merged
merged 3 commits into from
Nov 11, 2023

Conversation

solarispika
Copy link
Contributor

  • Allocate sufficient buffer for long file paths on macOS
  • Fix building tests on macOS using CMake
  • Fix compiler warnings

@solarispika solarispika marked this pull request as draft November 10, 2023 19:31
@solarispika solarispika marked this pull request as ready for review November 10, 2023 19:34
Copy link
Owner

@SpartanJ SpartanJ left a comment

Choose a reason for hiding this comment

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

Thanks! I left a couple of comments.

src/efsw/FileSystem.cpp Outdated Show resolved Hide resolved
src/test/efsw-test.cpp Show resolved Hide resolved
Copy link
Contributor Author

@solarispika solarispika left a comment

Choose a reason for hiding this comment

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

BTW, there is also a warning when compile with debug config on macOS.

/Users/user/Programming/efsw/src/efsw/WatcherKqueue.cpp:439:14: warning: variable 's_fc' set but not used [-Wunused-but-set-variable]
        static long s_fc = 0;
                    ^
1 warning generated.

I am not sure how to fix it in a neat cross platform way without using C++17 [[maybe_unused]] attribute.

src/efsw/FileSystem.cpp Outdated Show resolved Hide resolved
src/test/efsw-test.cpp Show resolved Hide resolved
@SpartanJ
Copy link
Owner

BTW, there is also a warning when compile with debug config on macOS.

/Users/user/Programming/efsw/src/efsw/WatcherKqueue.cpp:439:14: warning: variable 's_fc' set but not used [-Wunused-but-set-variable]
        static long s_fc = 0;
                    ^
1 warning generated.

I am not sure how to fix it in a neat cross platform way without using C++17 [[maybe_unused]] attribute.

Feel free to remove s_fc all-together, simply change the debug message from:

			efDEBUG( "Started using WatcherGeneric, reached file descriptors limit: %ld. Folders "
					 "added: %ld\n",
					 mWatcher->mFileDescriptorCount, s_fc );

to

			efDEBUG( "Started using WatcherGeneric, reached file descriptors limit: %ld.",
					 mWatcher->mFileDescriptorCount );

The previous implementation of FileSystem::precomposeFileName on macOS
truncated file paths longer than 255 bytes due to a fixed buffer size of 255
bytes. This could lead to unexpected behavior with long file paths.

This change uses CFStringGetMaximumSizeForEncoding to determine the needed
buffer size to fully contain the string. This allows handling file paths up to
the maximum possible length of LONG_MAX bytes, rather than imposing an
arbitrary fixed limit.

On the unlikely failure case, it returns empty string rather than truncating
the path. This prevents incorrect handling of impractically long paths in the
caller.
Copy link
Owner

@SpartanJ SpartanJ left a comment

Choose a reason for hiding this comment

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

Thank you very much for your collaboration!

@SpartanJ SpartanJ merged commit aae269e into SpartanJ:master Nov 11, 2023
3 checks passed
@solarispika solarispika deleted the fix/macos-path-handling branch November 11, 2023 17:22
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.

2 participants