Skip to content

Fix file watch for paths containing percent-encoded characters - #16

Open
stephanedupont wants to merge 1 commit into
christianselig:mainfrom
stephanedupont:fix-file-watch-percent-encoded-path
Open

Fix file watch for paths containing percent-encoded characters#16
stephanedupont wants to merge 1 commit into
christianselig:mainfrom
stephanedupont:fix-file-watch-percent-encoded-path

Conversation

@stephanedupont

Copy link
Copy Markdown

Fixes #15

setUpFileWatch() builds the path it passes to open(_:O_EVTONLY) from directoryURL.path(). URL.path() defaults to percentEncoded: true, so any directory whose path contains characters that get percent-encoded (most commonly a space) is handed to open() still encoded.

For example, the default Application Support location becomes:

.../Library/Application%20Support/<bundleID>/...

open() expects a real filesystem path, not a URL-encoded one. There is no directory literally named Application%20Support, so open() returns -1, the fileDescriptor > 0 guard fails, and the watch silently fails with:

Failed to set up file watch due to invalid file descriptor

This affects any store placed under Library/Application Support (Apple's recommended location for this kind of file). Reads/writes are unaffected because they go through NSFileCoordinator/URL-based APIs; only the open()-based watch breaks.

Using path(percentEncoded: false) passes a properly decoded filesystem path to open(), so the watch sets up correctly.

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.

Failed to set up file watch due to invalid file descriptor

1 participant