Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions Sources/PrivMXEndpointSwift/Errors/PrivMXEndpointError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public enum PrivMXEndpointError : Error{
/// Falied to delete KVDB Entries.
case failedDeletingKvdbEntries(privmx.InternalError)

case failedSyncingFile(privmx.InternalError)

/// Gets the Message of the error.
///
Expand Down Expand Up @@ -384,6 +385,7 @@ public enum PrivMXEndpointError : Error{
.failedCheckingifStringIsBase64(let err),
.failedTrimmingString(let err),
.failedSplittingString(let err),
.failedSyncingFile(let err),
.failedGeneratingBIP39(let err):
return String(err.message)
}
Expand Down Expand Up @@ -505,6 +507,7 @@ public enum PrivMXEndpointError : Error{
.failedCheckingifStringIsBase64(let err),
.failedTrimmingString(let err),
.failedSplittingString(let err),
.failedSyncingFile(let err),
.failedGeneratingBIP39(let err):
return err.code.value
}
Expand Down Expand Up @@ -625,6 +628,7 @@ public enum PrivMXEndpointError : Error{
.failedCheckingifStringIsBase64(let err),
.failedTrimmingString(let err),
.failedSplittingString(let err),
.failedSyncingFile(let err),
.failedGeneratingBIP39(let err):
return String(err.name)
}
Expand Down Expand Up @@ -745,6 +749,7 @@ public enum PrivMXEndpointError : Error{
.failedCheckingifStringIsBase64(let err),
.failedTrimmingString(let err),
.failedSplittingString(let err),
.failedSyncingFile(let err),
.failedGeneratingBIP39(let err):
return String(err.description)
}
Expand Down Expand Up @@ -865,6 +870,7 @@ public enum PrivMXEndpointError : Error{
.failedCheckingifStringIsBase64(let err),
.failedTrimmingString(let err),
.failedSplittingString(let err),
.failedSyncingFile(let err),
.failedGeneratingBIP39(let err):
if let scope = err.scope.value{
return String(scope)
Expand Down
25 changes: 20 additions & 5 deletions Sources/PrivMXEndpointSwift/Stores/StoreApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,18 @@ public class StoreApi{

/// Writes a chunk of data to an open file on the platform.
///
/// - Parameters:
/// - handle: The handle to the open file.
/// - dataChunk: The chunk of data to be written to the file.
/// - Parameter handle: The handle to the open file.
/// - Parameter dataChunk: The chunk of data to be written to the file.
/// - Parameter truncate: truncate the file from: current pos + dataChunk size
///
/// - Throws: `PrivMXEndpointError.failedWritingToFile` if writing to the file fails.
public func writeToFile(
handle: privmx.StoreFileHandle,
dataChunk: privmx.endpoint.core.Buffer
dataChunk: privmx.endpoint.core.Buffer,
truncate: Bool = false
) throws -> Void{

let res = api.writeToFile(handle,dataChunk)
let res = api.writeToFile(handle,dataChunk,truncate)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedWritingToFile(res.error.value!)
}
Expand All @@ -490,6 +491,20 @@ public class StoreApi{
}
}

/// Synchronize file handle data with newset data on serwer.
///
/// - Parameter handle: Store File handle to sync
///
/// - Throws: if the operation fails.
public func syncFile(
handle: privmx.StoreFileHandle
) throws -> Void {
let res = api.syncFile(handle)
guard res.error.value == nil else {
throw PrivMXEndpointError.failedSyncingFile(res.error.value!)
}
}

/// Subscribe for the Store events on the given subscription query.
///
/// - Parameter subscriptionQueries: list of queries
Expand Down
28 changes: 27 additions & 1 deletion Sources/PrivMXEndpointSwiftNative/NativeStoreApiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ ResultWithError<core::Buffer> NativeStoreApiWrapper::readFromFile(StoreFileHandl
}

ResultWithError<std::nullptr_t> NativeStoreApiWrapper::writeToFile(StoreFileHandle handle,
const core::Buffer& dataChunk){
const core::Buffer& dataChunk,
bool truncate = false){
ResultWithError<std::nullptr_t> res;
try{
getapi()->writeToFile(handle, dataChunk);
Expand Down Expand Up @@ -501,6 +502,31 @@ ResultWithError<std::nullptr_t> NativeStoreApiWrapper::deleteStore(const std::st
return res;
}

ResultWithError<std::nullptr_t> NativeStoreApiWrapper::syncFile(const StoreFileHandle handle){
ResultWithError<std::nullptr_t> res;
try {
getapi()->syncFile(handle);
}catch(core::Exception& err){
res.error = {
.name = err.getName(),
.code = err.getCode(),
.scope = err.getScope(),
.description = err.getDescription(),
.message = err.what()
};
}catch (std::exception & err) {
res.error ={
.name = "std::Exception",
.message = err.what()
};
}catch (...) {
res.error ={
.name = "Unknown Exception",
.message = "Failed to work"
};
}
return res;
}

ResultWithError<SubscriptionIdVector> NativeStoreApiWrapper::subscribeFor(const SubscriptionQueryVector& subscriptionQueries){
ResultWithError<SubscriptionIdVector> res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class NativeStoreApiWrapper{
* @return `ResultWithError` structure for error handling.
*/
ResultWithError<std::nullptr_t> writeToFile(const StoreFileHandle handle,
const endpoint::core::Buffer& dataChunk);
const endpoint::core::Buffer& dataChunk,
bool truncate);

/**
* Reads from an opened file.
Expand Down Expand Up @@ -238,6 +239,8 @@ class NativeStoreApiWrapper{
*/
ResultWithError<std::nullptr_t> deleteFile(const std::string& fileId);

ResultWithError<std::nullptr_t> syncFile(const StoreFileHandle handle);

/**
* Subscribe for the Thread events on the given subscription query.
*
Expand Down