minor refactoring
- untangle `CacheFile::{rewind_chunk, abort_upload}`
- change `file::Uploading::rewind` signature to a more "builder"esque pattern
This commit is contained in:
parent
d55684096f
commit
2cc13f24e7
2 changed files with 15 additions and 18 deletions
|
|
@ -169,23 +169,22 @@ impl CacheFile {
|
|||
}
|
||||
|
||||
pub fn rewind_chunk(mut self) -> Option<Self> {
|
||||
self.uploading = Some(
|
||||
self.uploading
|
||||
let upl = self
|
||||
.uploading
|
||||
.take()
|
||||
.expect("rewind_chunk called while not uploading")
|
||||
.rewind()?,
|
||||
);
|
||||
.expect("rewind_chunk called while not uploading");
|
||||
|
||||
self.uploading = Some(upl.rewind()?);
|
||||
Some(self)
|
||||
}
|
||||
|
||||
pub fn abort_upload(&mut self) {
|
||||
self.files.push_front(
|
||||
self.uploading
|
||||
let upl = self
|
||||
.uploading
|
||||
.take()
|
||||
.expect("abort_upload called while not uploading")
|
||||
.abort(),
|
||||
);
|
||||
.expect("abort_upload called while not uploading");
|
||||
|
||||
self.files.push_front(upl.abort());
|
||||
}
|
||||
|
||||
pub fn share_notify(&self, client: &impl Client) -> crate::Result<()> {
|
||||
|
|
|
|||
|
|
@ -46,13 +46,11 @@ impl Uploading {
|
|||
self.offset
|
||||
}
|
||||
|
||||
pub fn rewind(self) -> Option<Self> {
|
||||
pub fn rewind(mut self) -> Option<Self> {
|
||||
if let Some(last_offset) = self.last_offset {
|
||||
Some(Self {
|
||||
last_offset: None,
|
||||
offset: last_offset,
|
||||
..self
|
||||
})
|
||||
self.last_offset = None;
|
||||
self.offset = last_offset;
|
||||
Some(self)
|
||||
} else {
|
||||
warn!("attempted to rewind twice");
|
||||
None
|
||||
|
|
|
|||
Loading…
Reference in a new issue