Skip to content

Commit

Permalink
Merge 98b1ee1 into 81ed943
Browse files Browse the repository at this point in the history
  • Loading branch information
desistefanova committed Mar 2, 2022
2 parents 81ed943 + 98b1ee1 commit 3d25fac
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ x.x.x Release notes (yyyy-MM-dd)
* Added support for opening Realm in read-only mode. ([#260](https://github.com/realm/realm-dart/pull/260))
* Primary key fields no longer required to be `final` in data model classes ([#240](https://github.com/realm/realm-dart/pull/240))
* List fields no longer required to be `final` in data model classes. ([#253](https://github.com/realm/realm-dart/pull/253))
* Support custom FIFO sperial files paths. ([#284](https://github.com/realm/realm-dart/pull/284))

### Compatibility
* Dart ^2.15 on Windows, MacOS and Linux
Expand Down
21 changes: 20 additions & 1 deletion lib/src/configuration.dart
Expand Up @@ -36,14 +36,23 @@ class Configuration {
RealmSchema get schema => _schema;

/// Creates a [Configuration] with schema objects for opening a [Realm].
///
/// [fifoFilesFallbackPath] is a custom directory for storing FIFO special files
/// in case the Realm file is in a location that does not allow the creation of FIFO special files.
///
/// [readOnly] controls whether a [Realm] is opened as readonly.
/// This allows opening it from locked locations such as resources,
/// bundled with an application. The realm file must already exists.
Configuration(List<SchemaObject> schemaObjects, {bool readOnly = false})
Configuration(List<SchemaObject> schemaObjects, {String? fifoFilesFallbackPath, bool readOnly = false})
: _schema = RealmSchema(schemaObjects),
_handle = realmCore.createConfig() {
schemaVersion = 0;
path = defaultPath;

if (fifoFilesFallbackPath?.isNotEmpty ?? false) {
this.fifoFilesFallbackPath = fifoFilesFallbackPath!;
}

if (readOnly) {
isReadOnly = true;
}
Expand Down Expand Up @@ -97,6 +106,16 @@ class Configuration {
/// The realm file must already exists at [path]
bool get isReadOnly => realmCore.getConfigReadOnly(this);
set isReadOnly(bool value) => realmCore.setConfigReadOnly(this, value);

/// Gets or sets a value of FIFO special files location.
/// Opening a Realm creates a number of FIFO special files in order to
/// coordinate access to the Realm across threads and processes. If the Realm file is stored in a location
/// that does not allow the creation of FIFO special files (e.g. FAT32 filesystems), then the Realm cannot be opened.
/// In that case Realm needs a different location to store these files and this property defines that location.
/// The FIFO special files are very lightweight and the main Realm file will still be stored in the location defined
/// by the [path] you property. This property is ignored if the directory defined by [path] allow FIFO special files.
String get fifoFilesFallbackPath => realmCore.getConfigFifoPath(this);
set fifoFilesFallbackPath(String value) => realmCore.setConfigFifoPath(this, value);
}

/// A collection of properties describing the underlying schema of a [RealmObject].
Expand Down
10 changes: 10 additions & 0 deletions lib/src/native/realm_core.dart
Expand Up @@ -163,6 +163,16 @@ class _RealmCore {
_realmLib.realm_config_set_schema_mode(config.handle._pointer, mode);
}

String getConfigFifoPath(Configuration config) {
return _realmLib.realm_config_get_fifo_path(config.handle._pointer).cast<Utf8>().toDartString();
}

void setConfigFifoPath(Configuration config, String path) {
return using((Arena arena) {
_realmLib.realm_config_set_fifo_path(config.handle._pointer, path.toUtf8Ptr(arena));
});
}

ConfigHandle createConfig() {
final configPtr = _realmLib.realm_config_new();
return ConfigHandle._(configPtr);
Expand Down
6 changes: 6 additions & 0 deletions test/configuration_test.dart
Expand Up @@ -108,4 +108,10 @@ Future<void> main([List<String>? args]) async {
expect(() => realm.write(() {}), throws<RealmException>("Can't perform transactions on read-only Realms."));
realm.close();
});

test('Configuration - FIFO files fallback path', () {
Configuration config = Configuration([Car.schema], fifoFilesFallbackPath: "./fifo_folder");
var realm = Realm(config);
realm.close();
});
}

0 comments on commit 3d25fac

Please sign in to comment.