Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
15fe377
Move FFI callback to a global
za-creature Jan 6, 2025
93e60ad
Better mac build system
za-creature Jan 7, 2025
50044ab
Merge branch 'service' into darwin
za-creature Jan 14, 2025
a0be495
Expose LogLevel via FFI
za-creature Jan 14, 2025
70c7380
Move logInit to before Server.start
za-creature Jan 14, 2025
900150d
Remove old swift bindings
za-creature Jan 14, 2025
58d68cc
Add ouisync-service ffi bindings
za-creature Jan 14, 2025
21c95e4
Set explicit enum values
za-creature Jan 15, 2025
147958a
More explicit enum values
za-creature Jan 15, 2025
a3de4e7
Manually add missing enums
za-creature Jan 15, 2025
9ba2434
Remove no longer used channel errors
za-creature Jan 16, 2025
a181f85
Type-safe bindings
za-creature Jan 17, 2025
2e17b34
`swift build` compatibility
za-creature Jan 21, 2025
eee0b1d
Add trivial tests
za-creature Jan 21, 2025
7987aa4
Merge branch 'service' into darwin
za-creature Jan 21, 2025
1ec34c3
Add tests
za-creature Jan 24, 2025
e3e02cd
Merge branch 'develop' into darwin
za-creature Jan 24, 2025
3becae2
Finish tests
za-creature Jan 24, 2025
ee38525
Remove unsafe swift code
za-creature Jan 28, 2025
ba0d3fa
Include version hash in exported EntryType (now called StatEntry)
za-creature Jan 28, 2025
e0dca71
Add `root/target` to shared rust artifact pool on darwin
za-creature Jan 30, 2025
b4bddb6
Remove superflous logInit call
za-creature Jan 30, 2025
93ae842
Merge branch 'develop' into darwin
za-creature Feb 2, 2025
c1580d5
fix `cargo test` on darwin
za-creature Jan 30, 2025
69d332e
Readability
za-creature Jan 31, 2025
7fe9fc0
Update gradle
za-creature Feb 1, 2025
32448a5
Rename `listenerAddrs` property to mirror upstream
za-creature Feb 2, 2025
ea65398
Disable cli tests on macos without breaking other platforms
za-creature Feb 2, 2025
6aaa2ee
Export DirectoryEntry struct
za-creature Feb 3, 2025
77e9620
WIP: last commit
za-creature Apr 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions bindings/dart/lib/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,35 @@ import 'dart:ffi';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:ouisync/exception.dart';
import 'package:path/path.dart';

export 'bindings.g.dart';

sealed class EntryType {
static EntryType decode(Object foo) {
if (foo is! Map || foo.length != 1) { throw InvalidData("Not a one entry map"); }
return switch (foo.entries.first.key) {
"File" => EntryType_File(foo.entries.first.value),
"Directory" => EntryType_Directory(foo.entries.first.value),
final key => throw InvalidData("Unknown EntryType: $key")
};
}
}

// ignore: camel_case_types
class EntryType_File extends EntryType {
final Uint8List version;
EntryType_File(this.version);
}

// ignore: camel_case_types
class EntryType_Directory extends EntryType {
final Uint8List version;
EntryType_Directory(this.version);
}


/// Callback for `start_service` and `stop_service`.
typedef StatusCallback = Void Function(Pointer<Void>, Uint16);

Expand Down
22 changes: 0 additions & 22 deletions bindings/dart/lib/bindings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ enum AccessMode {

}

enum EntryType {
file,
directory,
;

static EntryType decode(int n) {
switch (n) {
case 1: return EntryType.file;
case 2: return EntryType.directory;
default: throw ArgumentError('invalid value: $n');
}
}

int encode() {
switch (this) {
case EntryType.file: return 1;
case EntryType.directory: return 2;
}
}

}

enum ErrorCode {
ok,
permissionDenied,
Expand Down
8 changes: 5 additions & 3 deletions bindings/dart/lib/ouisync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export 'bindings.dart'
show
AccessMode,
EntryType,
EntryType_File,
EntryType_Directory,
ErrorCode,
LogLevel,
NetworkEvent,
Expand Down Expand Up @@ -415,7 +417,7 @@ class Repository {
/// Returns the type (file, directory, ..) of the entry at [path]. Returns `null` if the entry
/// doesn't exists.
Future<EntryType?> entryType(String path) async {
final raw = await _client.invoke<int?>('repository_entry_type', {
final raw = await _client.invoke<Object?>('repository_entry_type', {
'repository': _handle,
'path': path,
});
Expand Down Expand Up @@ -641,13 +643,13 @@ class DirEntry {
static DirEntry decode(Object? raw) {
final map = raw as List<Object?>;
final name = map[0] as String;
final type = map[1] as int;
final type = map[1] as Object;

return DirEntry(name, EntryType.decode(type));
}

@override
String toString() => '$name (${entryType.name})';
String toString() => '$name ($entryType)';
}

/// A reference to a directory (folder) in a [Repository].
Expand Down
2 changes: 1 addition & 1 deletion bindings/dart/test/ouisync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void main() {
expect(await repo.entryType('dir'), isNull);

await Directory.create(repo, 'dir');
expect(await repo.entryType('dir'), equals(EntryType.directory));
expect(await repo.entryType('dir'), isA<EntryType_Directory>());

await Directory.remove(repo, 'dir');
expect(await repo.entryType('dir'), isNull);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ fun FolderScreen(
path = path,
onEntryClicked = { entry ->
when (entry.entryType) {
EntryType.FILE -> {
is EntryType.File -> {
navController.navigate(FileRoute(repositoryName, "$path/${entry.name}"))
}
EntryType.DIRECTORY -> {
is EntryType.Directory -> {
navController.navigate(FolderRoute(repositoryName, "$path/${entry.name}"))
}
}
Expand Down Expand Up @@ -324,8 +324,8 @@ fun FolderDetail(
modifier = Modifier.padding(PADDING).fillMaxWidth(),
) {
when (entry.entryType) {
EntryType.FILE -> Icon(Icons.Default.Description, "File")
EntryType.DIRECTORY -> Icon(Icons.Default.Folder, "Folder")
is EntryType.File -> Icon(Icons.Default.Description, "File")
is EntryType.Directory -> Icon(Icons.Default.Folder, "Folder")
}

Text(
Expand Down
Binary file modified bindings/kotlin/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion bindings/kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
21 changes: 12 additions & 9 deletions bindings/kotlin/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions bindings/kotlin/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package org.equalitie.ouisync.lib
* A directory entry
*
* @property name name of the entry.
* @property entryType type of the entry (i.e., file or directory).
* @property entryType type of the entry (i.e., file or directory) and version.
*/
data class DirectoryEntry(val name: String, val entryType: EntryType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ sealed class PeerState {
class Active(val runtimeId: String) : PeerState()
}

sealed class EntryType {
class File(var version: ByteArray) : EntryType()
class Directory(var version: ByteArray) : EntryType()
}

data class Progress(val value: Long, val total: Long)

internal sealed interface Response {
Expand Down Expand Up @@ -73,7 +78,7 @@ internal sealed interface Response {
"bytes" -> unpacker.unpackByteArray()
"directory" -> unpacker.unpackDirectory()
// Duration(Duration),
"entry_type" -> EntryType.decode(unpacker.unpackByte())
"entry_type" -> unpacker.unpackEntryType()
"file", "repository", "u64" -> unpacker.unpackLong()
"network_event" -> NetworkEvent.decode(unpacker.unpackByte())
// NetworkStats(Stats),
Expand Down Expand Up @@ -217,13 +222,36 @@ private fun MessageUnpacker.unpackDirectory(): Directory {
return Directory(entries)
}

internal fun MessageUnpacker.unpackEntryType(): EntryType {
val type = getNextFormat().getValueType()
return when (type) {
ValueType.NIL -> {
unpackNil()
throw IllegalArgumentException() // this is awkward but that's how bindgen does it too
}
ValueType.MAP -> {
val size = unpackMapHeader()
if (size != 1) {
throw Error.InvalidData("invalid EntryType payload: expected map of size 1, was $size")
}
val key = unpackString()
when (key) {
"File" -> EntryType.File(unpackByteArray())
"Directory" -> EntryType.Directory(unpackByteArray())
else -> throw Error.InvalidData("invalid EntryType case: '$key'")
}
}
else -> throw Error.InvalidData("invalid EntryType payload: expected NIL or MAP, was $type")
}
}

internal fun MessageUnpacker.unpackDirectoryEntry(): DirectoryEntry {
if (unpackArrayHeader() < 2) {
throw Error.InvalidData("invalid DirectoryEntry: too few elements")
}

val name = unpackString()
val entryType = EntryType.decode(unpackByte())
val entryType = unpackEntryType()

return DirectoryEntry(name, entryType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class RepositoryTest {
@Test
fun entryType() = runTest {
withRepo {
assertEquals(EntryType.DIRECTORY, it.entryType("/"))
assertTrue(it.entryType("/") is EntryType.Directory)
assertNull(it.entryType("missing.txt"))
}
}
Expand All @@ -171,7 +171,7 @@ class RepositoryTest {
File.create(repo, "foo.txt").close()

repo.moveEntry("foo.txt", "bar.txt")
assertEquals(EntryType.FILE, repo.entryType("bar.txt"))
assertTrue(repo.entryType("bar.txt") is EntryType.File)
assertNull(repo.entryType("foo.txt"))
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ class RepositoryTest {

val file = File.create(repo, name)
file.close()
assertEquals(EntryType.FILE, repo.entryType(name))
assertTrue(repo.entryType(name) is EntryType.File)

File.remove(repo, name)
assertNull(repo.entryType(name))
Expand Down Expand Up @@ -259,7 +259,7 @@ class RepositoryTest {
assertNull(repo.entryType(dirName))

Directory.create(repo, dirName)
assertEquals(EntryType.DIRECTORY, repo.entryType(dirName))
assertTrue(repo.entryType(dirName) is EntryType.Directory)

val dir0 = Directory.read(repo, dirName)
assertEquals(0, dir0.size)
Expand All @@ -269,7 +269,7 @@ class RepositoryTest {
val dir1 = Directory.read(repo, dirName)
assertEquals(1, dir1.size)
assertEquals(fileName, dir1.elementAt(0).name)
assertEquals(EntryType.FILE, dir1.elementAt(0).entryType)
assertTrue(dir1.elementAt(0).entryType is EntryType.File)

Directory.remove(repo, dirName, recursive = true)
assertNull(repo.entryType(dirName))
Expand Down
9 changes: 9 additions & 0 deletions bindings/swift/Ouisync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/OuisyncService.xcframework
/config.sh
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm
.netrc
14 changes: 14 additions & 0 deletions bindings/swift/Ouisync/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading