Skip to content

Commit

Permalink
Disabling sync/compact combo (#3899)
Browse files Browse the repository at this point in the history
* Disabling sync/compact combo
  • Loading branch information
Kenneth Geisshirt authored Dec 15, 2016
1 parent 8f3842e commit c20b487
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 2.2.2

### Object Server API Changes (In Beta)

* Disabled `Realm.compactRealm()` when sync is enabled as it might corrupt the Realm (https://github.com/realm/realm-core/issues/2345).

### Enhancements

* All major public classes are now non-final. This is mostly a compromise to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,14 @@ public void toString_nonEmpty() {
String configStr = config.toString();
assertTrue(configStr != null && !configStr.isEmpty());
}

// FIXME: This test can be removed when https://github.com/realm/realm-core/issues/2345 is resolved
@Test(expected = UnsupportedOperationException.class)
public void compact_NotAllowed() {
SyncUser user = createTestUser();
String url = "realm://objectserver.realm.io/default";
SyncConfiguration config = new SyncConfiguration.Builder(user, url).build();

Realm.compactRealm(config);
}
}
7 changes: 5 additions & 2 deletions realm/realm-library/src/main/java/io/realm/Realm.java
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,13 @@ public static boolean deleteRealm(RealmConfiguration configuration) {
*
* @param configuration a {@link RealmConfiguration} pointing to a Realm file.
* @return {@code true} if successful, {@code false} if any file operation failed.
* @throws IllegalArgumentException if the realm file is encrypted. Compacting an encrypted Realm file is not
* supported yet.
* @throws UnsupportedOperationException if Realm is synchronized.
*/
public static boolean compactRealm(RealmConfiguration configuration) {
// FIXME: remove this restriction when https://github.com/realm/realm-core/issues/2345 is resolved
if (configuration.isSyncConfiguration()) {
throw new UnsupportedOperationException("Compacting is not supported yet on synced Realms. See https://github.com/realm/realm-core/issues/2345");
}
return BaseRealm.compactRealm(configuration);
}

Expand Down

0 comments on commit c20b487

Please sign in to comment.