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

Optional Path for FlexibleSyncConfiguration isn't relative to App basePath #3383

Closed
moritz-mg opened this issue Jul 19, 2023 · 4 comments
Closed
Assignees

Comments

@moritz-mg
Copy link

moritz-mg commented Jul 19, 2023

What happened?

In Unity, creating a FlexibleSyncConfiguration with an optional path has that path Parented under Application.persistentDataPath, not the basePath that was given to the App.

Repro steps

Simple example scenario:

    var path = Path.Combine(Application.persistentDataPath, "app_path");
    Directory.CreateDirectory(path);
    var config = new AppConfiguration(RealmID)
    {
        BaseFilePath = path,
    };
    return App.Create(config);
    var config = new FlexibleSyncConfiguration(app.CurrentUser!, "realm_path") 
       {/* subscriptions etc. */};
    realm = await Realm.GetInstanceAsync(config);

Expected: Realm Files are created in $"{Application.persistentDataPath}/app_path/realm_path".

Actual: Realm Files are in $"{Application.persistentDataPath}/realm_path".

Related: "mongodb-realm" directory is created under $"{Application.persistentDataPath}/app_path" as expected.

Version

11.2.0

What Atlas Services are you using?

Both Atlas Device Sync and Atlas App Services

What type of application is this?

Unity

Client OS and version

Windows 11 x64 on Unity 2022.3.5f1

Code snippets

No response

Stacktrace of the exception/crash you're getting

No response

Relevant log output

No response

@moritz-mg moritz-mg changed the title Optional Path for FlexibleSyncConfiguration isn't relative to Application's pasePath Optional Path for FlexibleSyncConfiguration isn't relative to App basePath Jul 19, 2023
@moritz-mg
Copy link
Author

It's also a minor inconvenience / inconsistency that Realm paths are relative to the CWD / Application.persistenDataPath, but App BasePaths default to that, but must be given as absolute paths.

@nirinchev
Copy link
Member

You're right - this is an oversight, but we can't really change it easily as that would be a breaking change for many users (as their Realms will now move to a potentially new location). As a workaround, you can specify the absolute path to the Realm instead.

I can see we're missing some getters on the App class that would make that easier and I'll try to add them (notably, you don't have access to the BaseFilePath).

@nirinchev
Copy link
Member

I put up #3385 that adds BaseFilePath to the App instance, which should allow you to workaround the issue by constructing an absolute path:

var realmPath = Path.Combine(app.BaseFilePath, "realm_path");
var config = new FlexibleSyncConfiguration(app.CurrentUser!, realmPath);

I'm assuming this is sample code, but just in case, using hardcoded path for the Realm can be risky as you may end up with different users attempting to open the same file. This is why it's recommended that the Realm path incorporates the user id somewhere in there - e.g. Path.Combine(app.BaseFilePath, app.CurrentUser!.Id, "realm_path").

@nirinchev
Copy link
Member

I'm going to close this as not planned since we don't intend to change the behavior as that would be breaking. Once the new version is released, you should be able to more easily construct the absolute path relative to the app base path.

@nirinchev nirinchev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants