pub trait Transport: Send + Sync + Debug {
    // Required methods
    fn list_dir(&self, relpath: &str) -> Result<ListDir, Error>;
    fn read_file(&self, path: &str) -> Result<Bytes, Error>;
    fn create_dir(&self, relpath: &str) -> Result<(), Error>;
    fn write_file(&self, relpath: &str, content: &[u8]) -> Result<(), Error>;
    fn metadata(&self, relpath: &str) -> Result<Metadata, Error>;
    fn remove_file(&self, relpath: &str) -> Result<(), Error>;
    fn remove_dir_all(&self, relpath: &str) -> Result<(), Error>;
    fn sub_transport(&self, relpath: &str) -> Arc<dyn Transport>;

    // Provided method
    fn is_file(&self, path: &str) -> Result<bool, Error> { ... }
}
Expand description

Abstracted filesystem IO to access an archive.

This supports operations that are common across local filesystems, SFTP, and cloud storage, and that are intended to be sufficient to efficiently implement the Conserve format.

A transport has a root location, which will typically be the top directory of the Archive. Below that point everything is accessed with a relative path, expressed as a PathBuf.

All Transports must be Send + Sync, so they can be passed across or shared across threads.

Files in Conserve archives have bounded size and fit in memory so this does not need to support streaming or partial reads and writes.

Required Methods§

source

fn list_dir(&self, relpath: &str) -> Result<ListDir, Error>

List a directory, separating out file and subdirectory names.

Names are in the arbitrary order that they’re returned from the transport.

Any error during iteration causes overall failure.

source

fn read_file(&self, path: &str) -> Result<Bytes, Error>

Get one complete file into a caller-provided buffer.

Files in the archive are of bounded size, so it’s OK to always read them entirely into memory, and this is simple to support on all implementations.

source

fn create_dir(&self, relpath: &str) -> Result<(), Error>

Create a directory, if it does not exist.

If the directory already exists, it’s not an error.

This function does not create missing parent directories.

source

fn write_file(&self, relpath: &str, content: &[u8]) -> Result<(), Error>

Write a complete file.

As much as possible, the file should be written atomically so that it is only visible with the complete content. On a local filesystem the content is written to a temporary file and then renamed. If a temporary file is used, the name should start with crate::TMP_PREFIX.

If the file exists it is replaced. (Across transports, and particularly on S3, we can’t rely on detecting existing files.)

source

fn metadata(&self, relpath: &str) -> Result<Metadata, Error>

Get metadata about a file.

source

fn remove_file(&self, relpath: &str) -> Result<(), Error>

Delete a file.

source

fn remove_dir_all(&self, relpath: &str) -> Result<(), Error>

Delete a directory and all its contents.

source

fn sub_transport(&self, relpath: &str) -> Arc<dyn Transport>

Make a new transport addressing a subdirectory.

Provided Methods§

source

fn is_file(&self, path: &str) -> Result<bool, Error>

Check if a regular file exists.

Trait Implementations§

source§

impl AsRef<dyn Transport> for LocalTransport

source§

fn as_ref(&self) -> &(dyn Transport + 'static)

Converts this type into a shared reference of the (usually inferred) input type.

Implementors§