pub struct Files<M: FilesMode = Writer> { /* private fields */ }Expand description
Owns storage, database file operations and the device’s file area
(Appendix F.3), for the store’s writer or a read-only handle
(Files<ReadOnly>), which only reads files and keeps its cache. The
writer’s starts one commit-driven worker, for uploads and pins; no sync
loop or timer is created. Call close before closing the database.
Implementations§
Source§impl Files
impl Files
Sourcepub async fn prepare_pin(
&self,
files: &[FileRef],
) -> Result<PreparedPin, FileReadError>
pub async fn prepare_pin( &self, files: &[FileRef], ) -> Result<PreparedPin, FileReadError>
Prepare a pin of stored files (§17.8): download what each lacks, up
to the download limit at once, into a whole cache copy written,
synced and checked against its content hash, or note a checked whole
copy already kept. Nothing is pinned until a write commits the
result with its pin step. Each file’s download failure is its
stored bytes’ pending record, as for any pin; a download that
succeeds clears it. A file only on one device, this one included
while it uploads, is refused: only stored bytes are kept. So is one
whose record goes, or leaves its stored bytes, while they download
(NoLongerStored). While the network is metered and the app moves
files only on unmetered networks, the downloads wait before asking
storage for bytes (§17.8).
Source§impl Files
impl Files
Sourcepub async fn prepare_device_only(
&self,
folder: &Path,
files: Vec<(FileId, RelativePath)>,
cancel: &Receiver<bool>,
progress: Sender<Option<Progress<DeviceOnlyStep>>>,
) -> Result<PreparedDeviceOnly, DeviceOnlyError>
pub async fn prepare_device_only( &self, folder: &Path, files: Vec<(FileId, RelativePath)>, cancel: &Receiver<bool>, progress: Sender<Option<Progress<DeviceOnlyStep>>>, ) -> Result<PreparedDeviceOnly, DeviceOnlyError>
Download each cloud file to its path under folder, for one write
to switch them all to this device only, each copy becoming the
original this device records (§17.3). Each download checks the
file’s content hash, and each copy is written under a temporary name
in its final folder and renamed once synced. Each name is written as
the one rule for every platform makes it, which keeps it inside the
folder. A path through a symbolic link below the folder, where
something is already, or naming what another path names once
written, case and Unicode form aside, is refused. progress hears
each file’s download and how many of its bytes, and of the call’s,
are down. Until it returns, cancel stops the call; a failure, a
panic in a download among them, or a cancel removes every copy and
folder the call made. The call waits once for a place of the app’s
budget, before it holds anything, and reads each file’s stream in it
in turn; its copy’s writer is outside the budget (§17.3).
Source§impl<M: FilesMode> Files<M>
impl<M: FilesMode> Files<M>
Sourcepub async fn open_file_stream(
&self,
file: &FileRef,
lease: &FileLease,
) -> Result<FileStream<M>, FileReadError>
pub async fn open_file_stream( &self, file: &FileRef, lease: &FileLease, ) -> Result<FileStream<M>, FileReadError>
Open the file as its record now stands: its bytes here while it is on
this device only, uploading or not, or else its cached or stored
bytes. A file only on another device can’t be read here (§17.7), and
only such a file fails with DeviceOnly: a file that leaves this
device only as it opens goes on as the record the open found says,
which never keeps it here. The stream holds one place of lease
until it drops.
Source§impl Files
impl Files
Sourcepub async fn file_status(
&self,
file: &FileRef,
) -> Result<FileStatus, FileReadError>
pub async fn file_status( &self, file: &FileRef, ) -> Result<FileStatus, FileReadError>
The file as its record now stands: a file this device uploads is judged from local facts with no storage request, one only on another device from its record, and a stored one by one fresh single-object status call for its fixed path. Network failures and denied access are errors, not absence.
Source§impl<M: FilesMode> Files<M>
impl<M: FilesMode> Files<M>
Sourcepub fn reads_awaiting_connection(&self) -> Receiver<usize>
pub fn reads_awaiting_connection(&self) -> Receiver<usize>
Follow how many reads wait for a coming connection now, for a test that goes on once a read waits.
Source§impl Files
impl Files
Sourcepub fn expect_connection(&self) -> ConnectionComing
pub fn expect_connection(&self) -> ConnectionComing
Note that a connection attempt is running: until the returned guard drops, reads that need storage wait for it rather than fail. The guard drops when the attempt ends, connected or not, and a store with no storage then reads as released.
Source§impl Files<ReadOnly>
impl Files<ReadOnly>
Sourcepub fn read_only(
database: FileDatabase<ReadOnly>,
directory: StoreDir,
storage: Option<Arc<dyn Storage>>,
send: Arc<SequenceState>,
waits: Arc<RetryWaits>,
ids: IdSourceRef,
transfers: Arc<TransferBudget>,
files: FileBudget,
clock: ClockRef,
network: NetworkView,
) -> Self
pub fn read_only( database: FileDatabase<ReadOnly>, directory: StoreDir, storage: Option<Arc<dyn Storage>>, send: Arc<SequenceState>, waits: Arc<RetryWaits>, ids: IdSourceRef, transfers: Arc<TransferBudget>, files: FileBudget, clock: ClockRef, network: NetworkView, ) -> Self
Compose a read-only handle’s file owner, which reads files and keeps its cache; it uploads, pins and records nothing, and runs no worker.
Source§impl Files
impl Files
Sourcepub fn uploads_parked_from_now(
&self,
) -> impl Future<Output = ()> + Send + 'static
pub fn uploads_parked_from_now( &self, ) -> impl Future<Output = ()> + Send + 'static
Each time the upload worker has taken every change, wake and due retry that was ready, and waits for the next.
Sourcepub fn new(
database: FileDatabase,
directory: StoreDir,
storage: Option<Arc<dyn Storage>>,
send: Arc<SequenceState>,
waits: Arc<RetryWaits>,
ids: IdSourceRef,
transfers: Arc<TransferBudget>,
files: FileBudget,
clock: ClockRef,
network: NetworkView,
) -> Self
pub fn new( database: FileDatabase, directory: StoreDir, storage: Option<Arc<dyn Storage>>, send: Arc<SequenceState>, waits: Arc<RetryWaits>, ids: IdSourceRef, transfers: Arc<TransferBudget>, files: FileBudget, clock: ClockRef, network: NetworkView, ) -> Self
Compose the writer’s file owner and start its upload worker. Storage may be absent while uploads wait.
Sourcepub fn transfer_limits(&self) -> TransferLimits
pub fn transfer_limits(&self) -> TransferLimits
The limits shared by this handle’s transfer consumers.
Sourcepub fn set_transfer_limits(&self, limits: TransferLimits)
pub fn set_transfer_limits(&self, limits: TransferLimits)
Change upload and download admission. The next upload to start sees the new upload limit; uploads in flight keep running. Active response bodies retain their leases until they finish or are dropped.
Sourcepub async fn retry_uploads_now(&self) -> Result<DrainOutcome, SyncError>
pub async fn retry_uploads_now(&self) -> Result<DrainOutcome, SyncError>
Optionally retry recoverable uploads early: the upload worker attempts every upload that can retry, whatever its wait, and this returns once each attempt has ended. Provider cooldowns and failures that never clear still hold (§17.9), and while uploads are paused only bound ones are tried; while sync is stopped none is (§17.4).
Sourcepub fn set_uploads_paused(
&self,
sql: &SqlContext<'_, '_>,
paused: bool,
) -> Result<(), DbError>
pub fn set_uploads_paused( &self, sql: &SqlContext<'_, '_>, paused: bool, ) -> Result<(), DbError>
Persist the pause setting, as a step of sql’s write; a running
trailing upload stops between confirmed parts, preserving its
provider session (E7). Bound uploads run on (§17.4). Once the write
commits, and before it returns, the copy parts check takes the new
setting, after any upload run that read the old one has acted on it:
so no retry asked after the write returns is answered from the
setting it replaced.
Sourcepub fn set_unmetered_only(
&self,
sql: &SqlContext<'_, '_>,
unmetered_only: bool,
) -> Result<(), DbError>
pub fn set_unmetered_only( &self, sql: &SqlContext<'_, '_>, unmetered_only: bool, ) -> Result<(), DbError>
Persist the setting to move files only on unmetered networks, as a
step of sql‘s write (§17.9): while the network is metered, a running
trailing upload stops between confirmed parts, as a pause stops it,
and pins’ downloads wait before their next request to storage. Bound
uploads run on. Once the write commits, and before it returns, the
uploads and downloads take the new setting, as they take a pause.
Sourcepub async fn set_storage(
&self,
storage: Option<Arc<dyn Storage>>,
ready: impl Future<Output = Result<(), SyncError>>,
) -> Result<(), SyncError>
pub async fn set_storage( &self, storage: Option<Arc<dyn Storage>>, ready: impl Future<Output = Result<(), SyncError>>, ) -> Result<(), SyncError>
Finish transfers before verifying and committing a connection change. No upload starts meanwhile. A failed setup leaves the current connection installed.
Trait Implementations§
Auto Trait Implementations§
impl<M = Writer> !RefUnwindSafe for Files<M>
impl<M = Writer> !UnwindSafe for Files<M>
impl<M> Freeze for Files<M>
impl<M> Send for Files<M>
impl<M> Sync for Files<M>
impl<M> Unpin for Files<M>
impl<M> UnsafeUnpin for Files<M>
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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