Skip to main content

FileStore

Struct FileStore 

Source
pub struct FileStore<'s, S, D> { /* private fields */ }
Expand description

Stores each upload in a new file, at a path the application chooses, as protocol-multipart’s Readable#save does.

destination is given the declared field’s path, such as avatar or photos[2], and returns the file’s path; it is never given the filename or media type the client declared, which must not choose where an upload is stored. Each file is created exclusively, so creating it fails if anything is at the path, including a symbolic link, and on Unix with permissions 0600 unless Self::with_permissions chooses others; the process’s umask may remove more. A path that already exists fails the upload, and the read, with io::ErrorKind::AlreadyExists, so destination should return a path that is new, such as one with a random or unique name in a directory only the server can write.

When an upload is aborted, which read_content does whenever writing or finishing it fails, its file is removed; a file that is already gone counts as removed. A failed write or finish leaves the file in place until then, so a caller driving the store itself must abort the upload too. The store only removes files it created, by the paths it created them at, so the directory should not be one that others can write. Files are closed when they finish, but not synchronized to storage. File operations run through the scheduler’s Blocking capability, so that they do not block an async worker, and content is gathered into writes of up to 64 KiB; only when the scheduler refuses to admit blocking work, such as after cancellation, is a file closed on the current thread.

The handle of a stored upload is its path.

Implementations§

Source§

impl<'s, S, D> FileStore<'s, S, D>
where S: Blocking + Sync, D: FnMut(&FieldPath) -> PathBuf + Send,

Source

pub fn new(scheduler: &'s S, destination: D) -> Self

A store creating files on scheduler’s blocking threads, at the paths destination gives.

Source

pub fn with_permissions(self, permissions: u32) -> Self

Create files with these permission bits, as for open(2)’s mode, rather than 0600. Only the permission bits, 0o777, are used: the setuid, setgid, and sticky bits are ignored. It is only available on Unix, where files have permission bits.

Trait Implementations§

Source§

impl<S, D> Debug for FileStore<'_, S, D>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, D> UploadStore for FileStore<'_, S, D>
where S: Blocking + Sync, D: FnMut(&FieldPath) -> PathBuf + Send,

Source§

type Handle = PathBuf

What the declared struct holds for a stored upload, such as a path.
Source§

type Upload = FileUpload

An upload being stored.
Source§

type Error = Error

Why a store operation failed.
Source§

async fn create( &mut self, head: &UploadHead, cancellation: &Cancellation, ) -> Result<FileUpload>

Begin storing an upload. When this fails, nothing of the upload is stored. Read more
Source§

async fn write( &mut self, upload: &mut FileUpload, content: &[u8], cancellation: &Cancellation, ) -> Result<()>

Store some of an upload’s content, after what was stored before. When this fails, the caller must abort the upload, as read_content does.
Source§

async fn finish( &mut self, upload: &mut FileUpload, cancellation: &Cancellation, ) -> Result<PathBuf>

Complete an upload whose content has all been written, returning its handle. When this fails, the caller must abort the upload, as read_content does.
Source§

async fn abort(&mut self, upload: FileUpload) -> Result<()>

Remove whatever was stored of an upload that was not finished, or whose finish failed. It is not cancellable, since it cleans up after a failure.
Source§

async fn remove(&mut self, handle: PathBuf) -> Result<()>

Remove a finished upload. It is not cancellable, since it cleans up after a failure.

Auto Trait Implementations§

§

impl<'s, S, D> Forget for FileStore<'s, S, D>

§

impl<'s, S, D> Freeze for FileStore<'s, S, D>
where &'s S: Freeze, D: Freeze,

§

impl<'s, S, D> RefUnwindSafe for FileStore<'s, S, D>

§

impl<'s, S, D> Send for FileStore<'s, S, D>
where &'s S: Send, D: Send,

§

impl<'s, S, D> Sync for FileStore<'s, S, D>
where &'s S: Sync, D: Sync,

§

impl<'s, S, D> Unpin for FileStore<'s, S, D>
where &'s S: Unpin, D: Unpin,

§

impl<'s, S, D> UnsafeUnpin for FileStore<'s, S, D>

§

impl<'s, S, D> UnwindSafe for FileStore<'s, S, D>

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.

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, 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.