Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Client for one mount. Cheap to clone, clones share the pool, the listeners and the event dispatcher. The last clone to drop closes everything. close does it at once for all clones.

Implementations§

Source§

impl Client

Source

pub fn stat_batch(&self, paths: &[String]) -> Result<Vec<StatResult>>

Returns attributes for many paths. The result has one entry per path in input order. Large inputs are split into several requests that run in parallel on the pool.

Source

pub fn read_file(&self, path: &str) -> Result<Vec<u8>>

Reads a whole file. A file that fits in one payload takes one request. A larger file is opened and read in chunks until end of file.

Source

pub fn write_file(&self, path: &str, data: &[u8], truncate: bool) -> Result<()>

Writes a whole file, creating it when missing. With truncate the old content is dropped first. Data larger than one payload is written through an opened file in chunks.

Source§

impl Client

Source

pub fn connect(path: impl AsRef<Path>) -> Result<Client>

Connects with default options (4 connections).

Source

pub fn connect_with(path: impl AsRef<Path>, opts: Options) -> Result<Client>

Connects with the given options. The first connection and handshake happen now, so a bad socket or version mismatch fails here.

Source

pub fn close(&self)

Ends all connections, watches and background threads. Later calls fail with an I/O error of kind ConnectionAborted. Dropping the last clone does the same.

Source

pub fn open(&self, path: &str, flags: u32, mode: u32) -> Result<File>

Opens a file. flags combine open_flag values. The file stays bound to the connection that opened it.

Source

pub fn utimens( &self, path: &str, atime_ns: Option<i64>, mtime_ns: Option<i64>, ) -> Result<()>

Sets times in nanoseconds since the epoch. None leaves that time unchanged.

Source

pub fn opendir(&self, path: &str) -> Result<Dir>

Opens a directory for paged listing. The directory stays bound to the connection that opened it.

Source

pub fn ls( &self, path: &str, max_entries: u32, cursor: &str, ) -> Result<(Vec<DirEntry>, String)>

Lists up to max_entries entries with their attributes. Pass an empty cursor to start, then the returned cursor to continue. An empty returned cursor means the listing is complete.

Source§

impl Client

Source

pub fn add_listener( &self, f: impl Fn(&Event) + Send + Sync + 'static, ) -> ListenerId

Adds a listener. Every listener gets every event, in order, on the dispatcher thread of this client. The call must return quickly. A slow listener makes the queue (1024 events) drop its oldest events, and every listener then gets one local Overflow event. A panic in a listener is caught and logged. With no listener, events go to the logger. A listener that holds a Client clone keeps the client open until close is called.

Source

pub fn remove_listener(&self, id: ListenerId)

Removes a listener. An unknown id does nothing.

Source

pub fn wait_warm(&self, id: u64, timeout: Duration) -> Result<()>

Waits until warm request id is done. A failed warm returns its failure as Error::Server. Waiting longer than timeout returns an I/O error of kind TimedOut. The client keeps the last 1024 finished warms, so a warm that ended before this call is not missed. The server is not polled.

Source§

impl Client

Source

pub fn ping(&self) -> Result<()>

Checks that the server answers.

Source

pub fn stat(&self, path: &str) -> Result<FileInfo>

Returns attributes for path.

Source

pub fn lstat(&self, path: &str) -> Result<FileInfo>

Returns attributes for path without following a final symlink.

Source

pub fn mkdir(&self, path: &str, mode: u32) -> Result<()>

Creates a directory.

Source

pub fn rmdir(&self, path: &str) -> Result<()>

Removes an empty directory.

Removes a file.

Source

pub fn rename(&self, from: &str, to: &str) -> Result<()>

Moves from to to.

Creates link_path pointing at target.

Returns the target of the symlink at path.

Creates new_path as a hard link to existing.

Source

pub fn chmod(&self, path: &str, mode: u32) -> Result<()>

Sets the mode of path.

Source

pub fn truncate(&self, path: &str, size: i64) -> Result<()>

Sets the size of the file at path.

Source

pub fn statfs(&self, path: &str) -> Result<StatfsInfo>

Returns capacity figures for the filesystem holding path.

Source

pub fn access(&self, path: &str, mode: u32) -> Result<()>

Checks permissions for path. mode is a bit mask of 4 (read), 2 (write), 1 (execute), or 0 (exists).

Source

pub fn remove_all(&self, path: &str) -> Result<u64>

Removes path and everything below it. Returns the removed entry count.

Source

pub fn warm_open(&self, path: &str) -> Result<u64>

Starts warming the file in the background and returns a warm id at once. A missing file is reported later as a warm_failed notice on the same connection. Fails at once when the mount has no local cache.

Source

pub fn warm_read(&self, path: &str, offset: i64, length: i64) -> Result<u64>

Starts reading a file in the background to warm the cache and returns a warm id at once. Offset 0 and length 0, the defaults, warm the whole file. A length of 0 with an offset warms to the end of the file.

Source§

impl Client

Source

pub fn read_dir_all(&self, path: &str) -> Result<Vec<DirEntry>>

Lists one directory completely by following the ls cursor. Fails with Error::TooManyEntries when the directory has more than DEFAULT_MAX_DIR_ENTRIES entries.

Source

pub fn read_dir_all_max( &self, path: &str, max_entries: usize, ) -> Result<Vec<DirEntry>>

Like read_dir_all with a caller-chosen entry limit.

Source

pub fn walk( &self, path: &str, f: impl FnMut(&str, &DirEntry) -> Result<()>, ) -> Result<()>

Visits every entry below path, depth first. f gets the directory path and the entry, which carries its attributes. The entries of a directory arrive in listing order and each subdirectory is visited after the directory that holds it. Symlinks are reported and not followed. The walk stops at the first error from ls or from f and returns it. No entry is skipped silently. The walk holds one page plus the queued directories, at most DEFAULT_MAX_WALK_PENDING, and fails with Error::TooManyEntries beyond that.

Source

pub fn walk_max( &self, path: &str, max_pending: usize, f: impl FnMut(&str, &DirEntry) -> Result<()>, ) -> Result<()>

Like walk with a caller-chosen limit on queued directories.

Source§

impl Client

Source

pub fn watch(&self, path: &str, recursive: bool, since: u64) -> Result<Watch>

Starts a watch on path. since asks for events after that sequence. The server keeps no history, so an older value yields one Overflow event. Pass 0 for new events only.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.