Skip to content

refactor: Added ability to inject custom directory for DataStoreFile - #612

Closed
Michael Artes (asmeili) wants to merge 10 commits into
optimizely:masterfrom
asmeili:artesmichael/make-data-store-more-flexible
Closed

Michael Artes (asmeili) wants to merge 10 commits into
optimizely:masterfrom
asmeili:artesmichael/make-data-store-more-flexible

Conversation

@asmeili

Copy link
Copy Markdown

Summary

  • Extended DataStoreFile to allow for injection of custom FileManager.SearchPathDirectory
  • Extended DefaultEventDispatcher to allow for injection of custom FileManager.SearchPathDirectory for DataStoreType.file

Users have been raising the issue that they see these technical files inside of their Files app, because the directory for DataStoreFile defaults to .documentsDirectory, which is visible to users. This change allows us to update the directory to .applicationSupportDirectory in DefaultEventDispatcher using DataStoreType.file(directory: .applicationSupportDirectory) and in DefaultDatafileHandler by overriding open func createDataStore(sdkKey: String) -> OPTDataStore.

Test plan

  • Added a new test to verify the custom directory is used by DataStoreFile

Issues

  • None

@asmeili

Copy link
Copy Markdown
Author

Hi Muzahidul Islam (@muzahidul-opti), could you please review this PR and let me know if any changes are required?

@100hp4ever

Copy link
Copy Markdown

lgtm

@muzahidul-opti

Copy link
Copy Markdown
Contributor

Hi Muzahidul Islam (@muzahidul-opti), could you please review this PR and let me know if any changes are required?

Sure, we will review it.

@asmeili

Copy link
Copy Markdown
Author

Hi Muzahidul Islam (@muzahidul-opti), are there any updates on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, CI failing could you please fix it?

@asmeili

Copy link
Copy Markdown
Author

Hi Muzahidul Islam (@muzahidul-opti), I fixed the build issue. Could you approve the CI runs to verify?

@asmeili

Copy link
Copy Markdown
Author

Hi Raju Ahmed (@raju-opti), could you take a look at this PR and approve the CI runs?

@coveralls

Coveralls (coveralls) commented Jul 6, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 93.934% (+0.005%) from 93.929% — asmeili:artesmichael/make-data-store-more-flexible into optimizely:master

@asmeili

Copy link
Copy Markdown
Author

Thanks for the review! I've merged the latest master into the branch, which should take care of the testThreadSafe failure (it's in LruCacheTests, unrelated to this change, looks flaky).

The remaining failures don't seem fixable from my side as a fork PR.

Could you check again Muzahidul Islam (@muzahidul-opti)?

Muzahidul Islam (muzahidul-opti) added a commit that referenced this pull request Oct 27, 2026
…ultEventDispatcher (#668)

* refactor: Added optional directory parameter to DataStoreFile

* refactor: Added ability to inject file data store directory into DefaultEventDispatcher

* test: Added test for DataStoreFile custom directory

* refactor: Updated to syntax supported by Swift 5.8 and lower

* Fixed build issues

* Fixed failing test

* [FSSDK-12251] fix: keep custom data store directory API source-compatible

Rework #612 so it adds API without breaking 6.x users:
- Restore `DataStoreType.file` (no associated value) so `.file` and `==` keep compiling
- Keep `DataStoreFile.init(storeName:async:)` designated so subclasses can call super.init
- Expose the directory via new convenience inits on DataStoreFile and DefaultEventDispatcher
  (new designated inits on open classes are flagged by diagnose-api-breaking-changes)
- Add a test for the dispatcher custom-directory path

Co-authored-by: artesmichael <michael.artes@icloud.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* [FSSDK-12251] fix: create custom data store directory if missing

Application Support isn't guaranteed to exist on iOS, and Data.write
doesn't create parent directories, so writes failed and saveItem
swallowed the error, silently dropping queued events.

Resolve the directory with url(for:in:appropriateFor:create: true).
If creation fails, the store keeps its default location.

Tests no longer pre-create the directory; add a test against a
directory that doesn't exist yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: artesmichael <michael.artes@icloud.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@muzahidul-opti

Copy link
Copy Markdown
Contributor

Hi Michael Artes (@asmeili), thank you for this contribution, and apologies for the long wait.

Since this is a fork PR, CI couldn't run on it, so we carried your changes through an internal PR instead: #668. It's merged and released in 6.0.1.

Closing this PR as superseded by #668. Thanks again for the fix.

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.

4 participants