ouisync

Struct Repository

Source
pub struct Repository { /* private fields */ }

Implementations§

Source§

impl Repository

Source

pub async fn create( params: &RepositoryParams<impl Recorder>, access: Access, ) -> Result<Self>

Creates a new repository.

Source

pub async fn open( params: &RepositoryParams<impl Recorder>, local_secret: Option<LocalSecret>, access_mode: AccessMode, ) -> Result<Self>

Opens an existing repository.

Source

pub async fn database_id(&self) -> Result<DatabaseId>

Source

pub async fn requires_local_secret_for_reading(&self) -> Result<bool>

Source

pub async fn requires_local_secret_for_writing(&self) -> Result<bool>

Source

pub async fn set_access( &self, read_change: Option<AccessChange>, write_change: Option<AccessChange>, ) -> Result<()>

Sets, unsets or changes local secrets for accessing the repository or disables the given access mode.

In order to enable or change a given access mode the repository must currently be in at least that access mode. Disabling an access mode doesn’t have this restriction.

Disabling a given access mode makes the repo impossible to be opened in that mode anymore. However, when the repo is currently in that mode it still remains in it until the repo is closed.

To restore a disabled mode the repo must first be put into that mode using Self::set_credentials() where the Credentials must be obtained from AccessSecrets with at least the mode one wants to restore.

If read or write is None then no change is made to that mode. If both are None then this function is a no-op.

Disabling the read mode while keeping write mode enabled is allowed but not very useful as write mode also grants read access.

Source

pub fn credentials(&self) -> Credentials

Gets the current credentials of this repository.

See also Self::set_credentials().

Source

pub fn secrets(&self) -> AccessSecrets

Source

pub fn access_mode(&self) -> AccessMode

Gets the current access mode of this repository.

Source

pub async fn set_access_mode( &self, access_mode: AccessMode, local_secret: Option<LocalSecret>, ) -> Result<()>

Switches the repository to the given mode.

The actual mode the repository gets switched to is the higher of the current access mode and the mode provided by local_key but at most the mode specified in access_mode (“higher” means according to AccessMode’s Ord impl, that is: Write > Read > Blind).

Source

pub async fn set_credentials(&self, credentials: Credentials) -> Result<()>

Overrides the current credentials of this repository.

This is useful for moving/renaming the repo database or to restore access which has been either disabled or it’s local secret lost.

§Move/rename the repo db
  1. Obtain the current credentials with Self::credentials() and keep them locally.
  2. Close the repo.
  3. Rename the repo database files(s).
  4. Open the repo from its new location in blind mode.
  5. Restore the credentials from step 1 with Self::set_credentials().
§Restore access
  1. Get the AccessSecrets the repository was originally created from (e.g., by extracting them from the original ShareToken).
  2. Construct Credentials using this access secrets and a random writer id.
  3. Restore the credentials with Self::set_credentials().
  4. Enable/change the access with Self::set_access().
Source

pub async fn unlock_secrets( &self, local_secret: LocalSecret, ) -> Result<AccessSecrets>

Source

pub fn metadata(&self) -> Metadata

Get accessor for repository metadata. The metadata are arbitrary key-value entries that are stored inside the repository but not synced to other replicas.

Source

pub async fn set_quota(&self, quota: Option<StorageSize>) -> Result<()>

Set the storage quota in bytes. Use None to disable quota. Default is None.

Source

pub async fn quota(&self) -> Result<Option<StorageSize>>

Get the storage quota in bytes or None if no quota is set.

Source

pub async fn set_block_expiration( &self, block_expiration: Option<Duration>, ) -> Result<()>

Set the duration after which blocks start to expire (are deleted) when not used. Use None to disable expiration. Default is None.

Source

pub fn block_expiration(&self) -> Option<Duration>

Get the block expiration duration. None means block expiration is not set.

Source

pub fn last_block_expiration_time(&self) -> Option<SystemTime>

Get the time when the last block expired or None if there are still some unexpired blocks. If block expiration is not enabled, always return None.

Source

pub async fn size(&self) -> Result<StorageSize>

Get the total size of the data stored in this repository.

Source

pub fn handle(&self) -> RepositoryHandle

Source

pub async fn get_read_password_salt(&self) -> Result<PasswordSalt>

Source

pub async fn get_write_password_salt(&self) -> Result<PasswordSalt>

Source

pub fn monitor(&self) -> &StateMonitor

Get the state monitor node of this repository.

Source

pub async fn export(&self, dst: &Path) -> Result<()>

Export the repository to the given file.

The repository is currently exported as read-only with no password. In the future other modes might be added.

Source

pub async fn lookup_type<P: AsRef<Utf8Path>>( &self, path: P, ) -> Result<EntryType>

Looks up an entry by its path. The path must be relative to the repository root. If the entry exists, returns its JointEntryType, otherwise returns EntryNotFound.

Source

pub async fn open_file<P: AsRef<Utf8Path>>(&self, path: P) -> Result<File>

Opens a file at the given path (relative to the repository root)

Source

pub async fn open_file_version<P: AsRef<Utf8Path>>( &self, path: P, branch_id: &PublicKey, ) -> Result<File>

Open a specific version of the file at the given path.

Source

pub async fn open_directory<P: AsRef<Utf8Path>>( &self, path: P, ) -> Result<JointDirectory>

Opens a directory at the given path (relative to the repository root)

Source

pub async fn create_file<P: AsRef<Utf8Path>>(&self, path: P) -> Result<File>

Creates a new file at the given path.

Source

pub async fn create_directory<P: AsRef<Utf8Path>>( &self, path: P, ) -> Result<Directory>

Creates a new directory at the given path.

Source

pub async fn remove_entry<P: AsRef<Utf8Path>>(&self, path: P) -> Result<()>

Removes the file or directory (must be empty) and flushes its parent directory.

Source

pub async fn remove_entry_recursively<P: AsRef<Utf8Path>>( &self, path: P, ) -> Result<()>

Removes the file or directory (including its content) and flushes its parent directory.

Source

pub async fn move_entry<S: AsRef<Utf8Path>, D: AsRef<Utf8Path>>( &self, src_dir_path: S, src_name: &str, dst_dir_path: D, dst_name: &str, ) -> Result<()>

Moves (renames) an entry from the source path to the destination path. If both source and destination refer to the same entry, this is a no-op.

Source

pub fn local_branch(&self) -> Result<Branch>

Returns the local branch or Error::PermissionDenied if this repo doesn’t have at least read access.

Source

pub async fn load_branches(&self) -> Result<Vec<Branch>>

Source

pub async fn get_branch_version_vector( &self, writer_id: &PublicKey, ) -> Result<VersionVector>

Returns version vector of the given branch. Works in all access moded.

Source

pub async fn get_merged_version_vector(&self) -> Result<VersionVector>

Returns the version vector calculated by merging the version vectors of all branches.

Source

pub fn subscribe(&self) -> Receiver<Event>

Subscribe to event notifications.

Source

pub async fn sync_progress(&self) -> Result<Progress>

Gets the syncing progress of this repository (number of downloaded blocks / number of all blocks)

Source

pub async fn check_integrity(&self) -> Result<bool>

Check integrity of the stored data.

Source

pub async fn cd<P: AsRef<Utf8Path>>(&self, path: P) -> Result<JointDirectory>

Source

pub async fn close(&self) -> Result<()>

Close all db connections held by this repository. After this function returns, any subsequent operation on this repository that requires to access the db returns an error.

Source

pub async fn debug_print_root(&self)

Source

pub async fn debug_print(&self, print: DebugPrinter)

Source

pub async fn count_blocks(&self) -> Result<u64>

Returns the total number of blocks in this repository. This is useful for diagnostics and tests.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T