pub struct Repository { /* private fields */ }
Implementations§
Source§impl Repository
impl Repository
Sourcepub async fn create(
params: &RepositoryParams<impl Recorder>,
access: Access,
) -> Result<Self>
pub async fn create( params: &RepositoryParams<impl Recorder>, access: Access, ) -> Result<Self>
Creates a new repository.
Sourcepub async fn open(
params: &RepositoryParams<impl Recorder>,
local_secret: Option<LocalSecret>,
access_mode: AccessMode,
) -> Result<Self>
pub async fn open( params: &RepositoryParams<impl Recorder>, local_secret: Option<LocalSecret>, access_mode: AccessMode, ) -> Result<Self>
Opens an existing repository.
pub async fn database_id(&self) -> Result<DatabaseId>
pub async fn requires_local_secret_for_reading(&self) -> Result<bool>
pub async fn requires_local_secret_for_writing(&self) -> Result<bool>
Sourcepub async fn set_access(
&self,
read_change: Option<AccessChange>,
write_change: Option<AccessChange>,
) -> Result<()>
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.
Sourcepub fn credentials(&self) -> Credentials
pub fn credentials(&self) -> Credentials
Gets the current credentials of this repository.
See also Self::set_credentials().
pub fn secrets(&self) -> AccessSecrets
Sourcepub fn access_mode(&self) -> AccessMode
pub fn access_mode(&self) -> AccessMode
Gets the current access mode of this repository.
Sourcepub async fn set_access_mode(
&self,
access_mode: AccessMode,
local_secret: Option<LocalSecret>,
) -> Result<()>
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).
Sourcepub async fn set_credentials(&self, credentials: Credentials) -> Result<()>
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
- Obtain the current credentials with Self::credentials() and keep them locally.
- Close the repo.
- Rename the repo database files(s).
- Open the repo from its new location in blind mode.
- Restore the credentials from step 1 with Self::set_credentials().
§Restore access
- Get the
AccessSecrets
the repository was originally created from (e.g., by extracting them from the originalShareToken
). - Construct
Credentials
using this access secrets and a random writer id. - Restore the credentials with Self::set_credentials().
- Enable/change the access with Self::set_access().
pub async fn unlock_secrets( &self, local_secret: LocalSecret, ) -> Result<AccessSecrets>
Sourcepub fn metadata(&self) -> Metadata
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.
Sourcepub async fn set_quota(&self, quota: Option<StorageSize>) -> Result<()>
pub async fn set_quota(&self, quota: Option<StorageSize>) -> Result<()>
Set the storage quota in bytes. Use None
to disable quota. Default is None
.
Sourcepub async fn quota(&self) -> Result<Option<StorageSize>>
pub async fn quota(&self) -> Result<Option<StorageSize>>
Get the storage quota in bytes or None
if no quota is set.
Sourcepub async fn set_block_expiration(
&self,
block_expiration: Option<Duration>,
) -> Result<()>
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
.
Sourcepub fn block_expiration(&self) -> Option<Duration>
pub fn block_expiration(&self) -> Option<Duration>
Get the block expiration duration. None
means block expiration is not set.
Sourcepub fn last_block_expiration_time(&self) -> Option<SystemTime>
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
.
Sourcepub async fn size(&self) -> Result<StorageSize>
pub async fn size(&self) -> Result<StorageSize>
Get the total size of the data stored in this repository.
pub fn handle(&self) -> RepositoryHandle
pub async fn get_read_password_salt(&self) -> Result<PasswordSalt>
pub async fn get_write_password_salt(&self) -> Result<PasswordSalt>
Sourcepub async fn export(&self, dst: &Path) -> Result<()>
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.
Sourcepub async fn lookup_type<P: AsRef<Utf8Path>>(
&self,
path: P,
) -> Result<EntryType>
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
.
Sourcepub async fn open_file<P: AsRef<Utf8Path>>(&self, path: P) -> Result<File>
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)
Sourcepub async fn open_file_version<P: AsRef<Utf8Path>>(
&self,
path: P,
branch_id: &PublicKey,
) -> Result<File>
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.
Sourcepub async fn open_directory<P: AsRef<Utf8Path>>(
&self,
path: P,
) -> Result<JointDirectory>
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)
Sourcepub async fn create_file<P: AsRef<Utf8Path>>(&self, path: P) -> Result<File>
pub async fn create_file<P: AsRef<Utf8Path>>(&self, path: P) -> Result<File>
Creates a new file at the given path.
Sourcepub async fn create_directory<P: AsRef<Utf8Path>>(
&self,
path: P,
) -> Result<Directory>
pub async fn create_directory<P: AsRef<Utf8Path>>( &self, path: P, ) -> Result<Directory>
Creates a new directory at the given path.
Sourcepub async fn remove_entry<P: AsRef<Utf8Path>>(&self, path: P) -> Result<()>
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.
Sourcepub async fn remove_entry_recursively<P: AsRef<Utf8Path>>(
&self,
path: P,
) -> Result<()>
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.
Sourcepub 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<()>
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.
Sourcepub fn local_branch(&self) -> Result<Branch>
pub fn local_branch(&self) -> Result<Branch>
Returns the local branch or Error::PermissionDenied
if this repo doesn’t have at least
read access.
pub async fn load_branches(&self) -> Result<Vec<Branch>>
Sourcepub async fn get_branch_version_vector(
&self,
writer_id: &PublicKey,
) -> Result<VersionVector>
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.
Sourcepub async fn get_merged_version_vector(&self) -> Result<VersionVector>
pub async fn get_merged_version_vector(&self) -> Result<VersionVector>
Returns the version vector calculated by merging the version vectors of all branches.
Sourcepub async fn sync_progress(&self) -> Result<Progress>
pub async fn sync_progress(&self) -> Result<Progress>
Gets the syncing progress of this repository (number of downloaded blocks / number of all blocks)
Sourcepub async fn check_integrity(&self) -> Result<bool>
pub async fn check_integrity(&self) -> Result<bool>
Check integrity of the stored data.
pub async fn cd<P: AsRef<Utf8Path>>(&self, path: P) -> Result<JointDirectory>
Sourcepub async fn close(&self) -> Result<()>
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.
pub async fn debug_print_root(&self)
pub async fn debug_print(&self, print: DebugPrinter)
Sourcepub async fn count_blocks(&self) -> Result<u64>
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§
impl !Freeze for Repository
impl !RefUnwindSafe for Repository
impl Send for Repository
impl Sync for Repository
impl Unpin for Repository
impl !UnwindSafe for Repository
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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