Struct zbox::Repo [−][src]
pub struct Repo { /* fields omitted */ }
An encrypted repository contains the whole file system.
A Repo
represents a secure collection which consists of files,
directories and their associated data. Similar to std::fs
, Repo
provides methods to manipulate the enclosed file system.
Create and open Repo
Repo
can be created on different storages using RepoOpener
. It uses
an URI-like string to specify its location. Supported storages are listed
below:
- OS file system based storage, location prefix:
file://
- Memory based storage, location prefix:
mem://
- SQLite based storage, location prefix:
sqlite://
- Redis based storage, location prefix:
redis://
Check details at: RepoOpener
Repo
can only be opened once at a time. After opened, it keeps locked
from other open attempts until it goes out scope.
Optionally, Repo
can also be opened in read-only
mode.
Examples
Create an OS file system based repository.
use zbox::{init_env, RepoOpener}; init_env(); let mut repo = RepoOpener::new() .create(true) .open("file:///path/to/repo", "pwd")?;
Create a memory based repository.
let mut repo = RepoOpener::new().create(true).open("mem://foo", "pwd")?;
Open a repository in read-only mode.
let mut repo = RepoOpener::new() .read_only(true) .open("file:///path/to/repo", "pwd")?;
Methods
impl Repo
[src]
impl Repo
pub fn exists(uri: &str) -> Result<bool>
[src]
pub fn exists(uri: &str) -> Result<bool>
Returns whether the URI points at an existing repository.
Existence check depends on the underlying storage implementation, for memory storage, it always returns false. For file storage, it will return if the specified path exists on the OS file system.
pub fn info(&self) -> RepoInfo
[src]
pub fn info(&self) -> RepoInfo
Get repository metadata infomation.
pub fn reset_password(
&mut self,
old_pwd: &str,
new_pwd: &str,
ops_limit: OpsLimit,
mem_limit: MemLimit
) -> Result<()>
[src]
pub fn reset_password(
&mut self,
old_pwd: &str,
new_pwd: &str,
ops_limit: OpsLimit,
mem_limit: MemLimit
) -> Result<()>
Reset password for the respository.
pub fn path_exists<P: AsRef<Path>>(&self, path: P) -> bool
[src]
pub fn path_exists<P: AsRef<Path>>(&self, path: P) -> bool
Returns whether the path points at an existing entity in repository.
path
must be an absolute path.
pub fn is_file<P: AsRef<Path>>(&self, path: P) -> bool
[src]
pub fn is_file<P: AsRef<Path>>(&self, path: P) -> bool
Returns whether the path exists in repository and is pointing at a regular file.
path
must be an absolute path.
pub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
[src]
pub fn is_dir<P: AsRef<Path>>(&self, path: P) -> bool
Returns whether the path exists in repository and is pointing at a directory.
path
must be an absolute path.
pub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File>
[src]
pub fn create_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File>
Create a file in read-write mode.
This function will create a file if it does not exist, and will truncate it if it does.
See the OpenOptions::open
function for more details.
pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File>
[src]
pub fn open_file<P: AsRef<Path>>(&mut self, path: P) -> Result<File>
Attempts to open a file in read-only mode.
path
must be an absolute path.
See the OpenOptions::open
function for more details.
Errors
This function will return an error if path does not already exist.
Other errors may also be returned according to OpenOptions::open
.
Examples
let mut f = repo.open_file("foo.txt")?;
pub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
[src]
pub fn create_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Creates a new, empty directory at the specified path.
path
must be an absolute path.
pub fn create_dir_all<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
[src]
pub fn create_dir_all<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Recursively create a directory and all of its parent components if they are missing.
path
must be an absolute path.
pub fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Vec<DirEntry>>
[src]
pub fn read_dir<P: AsRef<Path>>(&self, path: P) -> Result<Vec<DirEntry>>
Returns a vector of all the entries within a directory.
path
must be an absolute path.
pub fn metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>
[src]
pub fn metadata<P: AsRef<Path>>(&self, path: P) -> Result<Metadata>
Given a path, query the repository to get information about a file, directory, etc.
path
must be an absolute path.
pub fn history<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Version>>
[src]
pub fn history<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Version>>
Return a vector of history versions of a regular file.
path
must be an absolute path to a regular file.
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q
) -> Result<()>
[src]
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q
) -> Result<()>
Copies the content of one file to another.
This function will overwrite the content of to
.
If from
and to
both point to the same file, then this function will
do nothing.
from
and to
must be absolute paths to regular files.
pub fn remove_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
[src]
pub fn remove_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Removes a regular file from the repository.
path
must be an absolute path.
pub fn remove_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
[src]
pub fn remove_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Remove an existing empty directory.
path
must be an absolute path.
pub fn remove_dir_all<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
[src]
pub fn remove_dir_all<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Removes a directory at this path, after removing all its children. Use carefully!
path
must be an absolute path.
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q
) -> Result<()>
[src]
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(
&mut self,
from: P,
to: Q
) -> Result<()>
Rename a file or directory to a new name, replacing the original file if to already exists.
from
and to
must be absolute paths.