Repository navigation
[FSSDK-12251] feat: allow custom directory for DataStoreFile and DefaultEventDispatcher #668
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
Merged
Muzahidul Islam (muzahidul-opti)
merged 9 commits into
master
from
muzahidul/datastore-custom-directory
Oct 27, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8d5254e
refactor: Added optional directory parameter to DataStoreFile
b1e288a
refactor: Added ability to inject file data store directory into Defa…
106dc73
test: Added test for DataStoreFile custom directory
451bc0c
refactor: Updated to syntax supported by Swift 5.8 and lower
51634e2
Fixed build issues
4ba267a
Fixed failing test
9eceac7
[FSSDK-12251] fix: keep custom data store directory API source-compat…
muzahidul-opti 4e4b2c8
Merge branch 'master' into muzahidul/datastore-custom-directory
muzahidul-opti 6999d38
[FSSDK-12251] fix: create custom data store directory if missing
muzahidul-opti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target directory is never created, and
.applicationSupportDirectory— the directory this feature exists to enable — does not exist by default on iOS. Writes there fail silently and events are dropped.FileManager.urls(for:in:)returns the URL whether or not the folder exists on disk. iOS auto-createsDocuments,tmp, andLibrary/Caches, but notLibrary/Application Support— the app must create it. The old code only used.documentDirectory(always present), so this never mattered before.Downstream,
writeDatausesData.write(to:options:.atomic), which does not create intermediate directories and throws if the parent is missing.saveItemswallows that into a log line, so the failure is silent:Failure scenario (the PR's own example):
On a real app where
Library/Application Supporthasn't been created, everyeventQueue.savethrows and is swallowed,countstays 0,flushEventsfinds nothing — analytics events are silently lost. The datafile-cache path (createDataStore→DataStoreFile(directory: .applicationSupportDirectory)) fails the same way.Why the tests miss it: both new tests pre-create the directory before using the store (
DataStoreTests.testFileStoreCustomDirectorycallscreateDirectoryIfNeeded(...);EventDispatcherTests.testEventDispatcherFileCustomDirectorycallsFileManager.default.createDirectory(at: dirUrl, withIntermediateDirectories: true)), so they only exercise a precondition the feature never establishes itself.Proposed fix:
And drop the
createDirectorypre-steps from the new tests (or add a variant without them) so they actually prove the store is self-sufficient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks. Fixed in 6999d38.
FileManager.default.url(for:in:appropriateFor:create: true). This is Foundation's built-in way to create a standard directory if it's missing.try? createDirectoryfollowed by always settingurl, events would still be dropped in that rare case.testFileStoreCustomDirectoryandtestEventDispatcherFileCustomDirectory. I couldn't use Application Support to prove the directory gets created, because these tests have no host app. Application Support resolves to the simulator device's shared folder, which always exists and can't be deleted. So I addedtestFileStoreCreatesMissingDirectory, which uses.autosavedInformationDirectory(missing on a fresh simulator). It failed before the fix and passes with it.DataStoreTests,EventDispatcherTests,DatafileHandlerTests: 41/41 passed.diagnose-api-breaking-changes origin/master: no breaking changes.Could you re-review?