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> {
|
pub fn rewind_chunk(mut self) -> Option<Self> {
|
||||||
self.uploading = Some(
|
let upl = self
|
||||||
self.uploading
|
.uploading
|
||||||
.take()
|
.take()
|
||||||
.expect("rewind_chunk called while not uploading")
|
.expect("rewind_chunk called while not uploading");
|
||||||
.rewind()?,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
self.uploading = Some(upl.rewind()?);
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn abort_upload(&mut self) {
|
pub fn abort_upload(&mut self) {
|
||||||
self.files.push_front(
|
let upl = self
|
||||||
self.uploading
|
.uploading
|
||||||
.take()
|
.take()
|
||||||
.expect("abort_upload called while not uploading")
|
.expect("abort_upload called while not uploading");
|
||||||
.abort(),
|
|
||||||
);
|
self.files.push_front(upl.abort());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn share_notify(&self, client: &impl Client) -> crate::Result<()> {
|
pub fn share_notify(&self, client: &impl Client) -> crate::Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,11 @@ impl Uploading {
|
||||||
self.offset
|
self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rewind(self) -> Option<Self> {
|
pub fn rewind(mut self) -> Option<Self> {
|
||||||
if let Some(last_offset) = self.last_offset {
|
if let Some(last_offset) = self.last_offset {
|
||||||
Some(Self {
|
self.last_offset = None;
|
||||||
last_offset: None,
|
self.offset = last_offset;
|
||||||
offset: last_offset,
|
Some(self)
|
||||||
..self
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
warn!("attempted to rewind twice");
|
warn!("attempted to rewind twice");
|
||||||
None
|
None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue