From 46a82277af260e95629b6f893e17a69a1a754b3e Mon Sep 17 00:00:00 2001 From: Ferdinando Papale <4850119+papafe@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:00:12 +0100 Subject: [PATCH] Updated core to 13.26.0 (#3502) * Updated core to 13.26.0 * Corrected errors * Set default to true * Apply suggestions from code review Co-authored-by: Nikola Irinchev --------- Co-authored-by: Nikola Irinchev --- CHANGELOG.md | 5 +- Realm/Realm/Handles/AppHandle.cs | 58 ++++++++++++------- .../GuidRepresentationMigrationTests.cs | 4 +- Tests/Realm.Tests/Sync/SyncTestBase.cs | 25 +++++++- wrappers/realm-core | 2 +- wrappers/src/app_cs.cpp | 21 +++++-- 6 files changed, 83 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 345aebdbb8..1c242a02ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,12 +17,15 @@ * Fixed several errors that could cause a crash of the sync client. (Core 13.25.0) * Bad performance of initial Sync download involving many backlinks. (Core 13.25.1) * Explicitly bumped the minimum version of System.Net.Security to 4.3.2 as 4.3.0 has been marked as vulnerable (more details can be found in the deprecation notice on the [NuGet page](https://www.nuget.org/packages/System.Net.Security/4.3.0)). +* Handle EOPNOTSUPP when using posix_fallocate() and fallback to manually consume space. This should enable android users to open a Realm on restrictive filesystems. (Core 13.26.0) +* Application may crash with incoming_changesets.size() != 0 when a download message is mistaken for a bootstrap message. This can happen if the synchronization session is paused and resumed at a specific time. (Core 13.26.0) +* Fixed errors complaining about missing symbols such as `__atomic_is_lock_free` on ARMv7 Linux (Core 13.26.0) ### Compatibility * Realm Studio: 13.0.0 or later. ### Internal -* Using Core 13.25.1. +* Using Core 13.26.0. ## 11.6.1 (2023-11-17) diff --git a/Realm/Realm/Handles/AppHandle.cs b/Realm/Realm/Handles/AppHandle.cs index 543565df1d..6a65979ec3 100644 --- a/Realm/Realm/Handles/AppHandle.cs +++ b/Realm/Realm/Handles/AppHandle.cs @@ -100,6 +100,9 @@ public static extern IntPtr get_user_for_testing( [MarshalAs(UnmanagedType.LPWStr)] string access_token_buf, IntPtr access_token_len, out NativeException ex); + [DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_set_fake_sync_route_for_testing", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr set_fake_sync_route_for_testing(AppHandle app, out NativeException ex); + [DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_clear_cached_apps", CallingConvention = CallingConvention.Cdecl)] public static extern void clear_cached_apps(out NativeException ex); @@ -107,7 +110,7 @@ public static extern IntPtr get_user_for_testing( public static extern IntPtr get_base_file_path(AppHandle app, IntPtr buffer, IntPtr buffer_length, out NativeException ex); [DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_get_base_uri", CallingConvention = CallingConvention.Cdecl)] - public static extern StringValue get_base_uri(AppHandle app, out NativeException ex); + public static extern IntPtr get_base_uri(AppHandle app, IntPtr buffer, IntPtr buffer_length, out NativeException ex); [DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_get_id", CallingConvention = CallingConvention.Cdecl)] public static extern StringValue get_id(AppHandle app, out NativeException ex); @@ -307,23 +310,6 @@ public async Task DeleteUserAsync(SyncUserHandle user) } } - public void ResetForTesting() - { - NativeMethods.reset_for_testing(this); - } - - public SyncUserHandle GetUserForTesting(string id, string refreshToken, string accessToken) - { - var result = NativeMethods.get_user_for_testing( - this, - id, (IntPtr)id.Length, - refreshToken, (IntPtr)refreshToken.Length, - accessToken, (IntPtr)accessToken.Length, - out var ex); - ex.ThrowIfNecessary(); - return new SyncUserHandle(result); - } - public string GetBaseFilePath() { return MarshalHelpers.GetString((IntPtr buffer, IntPtr length, out bool isNull, out NativeException ex) => @@ -335,9 +321,13 @@ public string GetBaseFilePath() public Uri GetBaseUri() { - var value = NativeMethods.get_base_uri(this, out var ex); - ex.ThrowIfNecessary(); - return new Uri(value!); + var uriString = MarshalHelpers.GetString((IntPtr buffer, IntPtr length, out bool isNull, out NativeException ex) => + { + isNull = false; + return NativeMethods.get_base_uri(this, buffer, length, out ex); + })!; + + return new Uri(uriString); } public string GetId() @@ -356,6 +346,32 @@ public bool IsSameInstance(AppHandle other) protected override void Unbind() => NativeMethods.destroy(handle); + #region Testing + public void ResetForTesting() + { + NativeMethods.reset_for_testing(this); + } + + public SyncUserHandle GetUserForTesting(string id, string refreshToken, string accessToken) + { + var result = NativeMethods.get_user_for_testing( + this, + id, (IntPtr)id.Length, + refreshToken, (IntPtr)refreshToken.Length, + accessToken, (IntPtr)accessToken.Length, + out var ex); + ex.ThrowIfNecessary(); + return new SyncUserHandle(result); + } + + public void SetFakeSyncRouteForTesting() + { + NativeMethods.set_fake_sync_route_for_testing(this, out var ex); + ex.ThrowIfNecessary(); + } + + #endregion + [MonoPInvokeCallback(typeof(NativeMethods.UserCallback))] private static void HandleUserCallback(IntPtr tcs_ptr, IntPtr user_ptr, AppError error) { diff --git a/Tests/Realm.Tests/Database/GuidRepresentationMigrationTests.cs b/Tests/Realm.Tests/Database/GuidRepresentationMigrationTests.cs index 5d54e292d0..0984eda9ad 100644 --- a/Tests/Realm.Tests/Database/GuidRepresentationMigrationTests.cs +++ b/Tests/Realm.Tests/Database/GuidRepresentationMigrationTests.cs @@ -150,7 +150,7 @@ public void FlexibleSync_Subscriptions_MatchesGuid([Values(true, false)] bool us Realm.UseLegacyGuidRepresentation = useLegacyRepresentation; #pragma warning restore CS0618 // Type or member is obsolete - var config = GetFakeFLXConfig(); + var config = GetFakeFLXConfig(setFakeSyncRoute: true); config.Schema = new[] { typeof(GuidType), typeof(EmbeddedGuidType) }; using var realm = GetRealm(config); @@ -310,7 +310,7 @@ public void SynchronizedRealm_DoesntMigrate([Values(true, false)] bool useLegacy var expected = GetGuidObjects().ToArray(); - var config = GetFakeConfig(userId: "sync-guids-test-user"); + var config = GetFakeConfig(userId: "sync-guids-test-user", setFakeSyncRoute: true); config.Schema = new[] { typeof(GuidType), typeof(EmbeddedGuidType) }; TestHelpers.CopyBundledFileToDocuments("sync-guids.realm", config.DatabasePath); diff --git a/Tests/Realm.Tests/Sync/SyncTestBase.cs b/Tests/Realm.Tests/Sync/SyncTestBase.cs index 9af7590fbd..b7eaf3ef2b 100644 --- a/Tests/Realm.Tests/Sync/SyncTestBase.cs +++ b/Tests/Realm.Tests/Sync/SyncTestBase.cs @@ -138,6 +138,13 @@ protected User GetFakeUser(App? app = null, string? id = null, string? refreshTo return new User(handle, app); } + // This could be useful when opening a "fake" sync realm locally + protected void SetFakeSyncRoute(App? app) + { + app ??= DefaultApp; + app.Handle.SetFakeSyncRouteForTesting(); + } + protected async Task GetIntegrationRealmAsync(string? partition = null, App? app = null, int timeout = 10000) { var config = await GetIntegrationConfigAsync(partition, app); @@ -256,15 +263,29 @@ private static T UpdateConfig(T config) return config; } - protected PartitionSyncConfiguration GetFakeConfig(App? app = null, string? userId = null, string? optionalPath = null) + protected PartitionSyncConfiguration GetFakeConfig(App? app = null, string? userId = null, + string? optionalPath = null, bool setFakeSyncRoute = true) { var user = GetFakeUser(app, userId); + + if (setFakeSyncRoute) + { + SetFakeSyncRoute(app); + } + return UpdateConfig(new PartitionSyncConfiguration(Guid.NewGuid().ToString(), user, optionalPath)); } - protected FlexibleSyncConfiguration GetFakeFLXConfig(App? app = null, string? userId = null, string? optionalPath = null) + protected FlexibleSyncConfiguration GetFakeFLXConfig(App? app = null, string? userId = null, + string? optionalPath = null, bool setFakeSyncRoute = true) { var user = GetFakeUser(app, userId); + + if (setFakeSyncRoute) + { + SetFakeSyncRoute(app); + } + return UpdateConfig(new FlexibleSyncConfiguration(user, optionalPath)); } diff --git a/wrappers/realm-core b/wrappers/realm-core index 7227d6a447..a5e87a39cf 160000 --- a/wrappers/realm-core +++ b/wrappers/realm-core @@ -1 +1 @@ -Subproject commit 7227d6a447821c28895daa099b6c7cd4c99d461b +Subproject commit a5e87a39cffdcc591f3203c11cfca68100d0b9a6 diff --git a/wrappers/src/app_cs.cpp b/wrappers/src/app_cs.cpp index b7e5d48383..aae3cb6733 100644 --- a/wrappers/src/app_cs.cpp +++ b/wrappers/src/app_cs.cpp @@ -175,9 +175,10 @@ extern "C" { sync_client_config.custom_encryption_key = std::vector(key.begin(), key.end()); } - SharedApp app = app_config.use_cache - ? App::get_shared_app(std::move(config), std::move(sync_client_config)) - : App::get_uncached_app(std::move(config), std::move(sync_client_config)); + SharedApp app = App::get_app(app_config.use_cache ? + realm::app::App::CacheMode::Enabled : realm::app::App::CacheMode::Disabled, + std::move(config), + std::move(sync_client_config)); return new SharedApp(app); }); @@ -250,6 +251,15 @@ extern "C" { }); } + REALM_EXPORT void shared_app_set_fake_sync_route_for_testing(SharedApp& app, + NativeException::Marshallable& ex) + { + return handle_errors(ex, [&]() { + app->sync_manager()->set_sync_route("realm://www.test.com:1000"); + }); + } + + REALM_EXPORT void shared_app_remove_user(SharedApp& app, SharedSyncUser& user, void* tcs_ptr, NativeException::Marshallable& ex) { return handle_errors(ex, [&]() { @@ -318,10 +328,11 @@ extern "C" { }); } - REALM_EXPORT realm_string_t shared_app_get_base_uri(SharedApp& app, NativeException::Marshallable& ex) + REALM_EXPORT size_t shared_app_get_base_uri(SharedApp& app, uint16_t* buffer, size_t buffer_length, NativeException::Marshallable& ex) { return handle_errors(ex, [&]() { - return to_capi(app->base_url()); + std::string url(app->get_base_url()); + return stringdata_to_csharpstringbuffer(url, buffer, buffer_length); }); }