diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/object_table.rs | 43 | ||||
-rw-r--r-- | src/core/version_table.rs | 1 |
2 files changed, 33 insertions, 11 deletions
diff --git a/src/core/object_table.rs b/src/core/object_table.rs index e4c78524..98e8d636 100644 --- a/src/core/object_table.rs +++ b/src/core/object_table.rs @@ -61,11 +61,31 @@ pub struct ObjectVersion { pub mime_type: String, pub size: u64, - pub is_complete: bool, + pub state: ObjectVersionState, pub data: ObjectVersionData, } +#[derive(PartialEq, Clone, Copy, Debug, Serialize, Deserialize)] +pub enum ObjectVersionState { + Uploading, + Complete, + Aborted, +} + +impl ObjectVersionState { + fn max(self, other: Self) -> Self { + use ObjectVersionState::*; + if self == Aborted || other == Aborted { + Aborted + } else if self == Complete || other == Complete { + Complete + } else { + Uploading + } + } +} + #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub enum ObjectVersionData { DeleteMarker, @@ -74,8 +94,14 @@ pub enum ObjectVersionData { } impl ObjectVersion { - fn cmp_key(&self) -> (u64, &UUID) { - (self.timestamp, &self.uuid) + fn cmp_key(&self) -> (u64, UUID) { + (self.timestamp, self.uuid) + } + pub fn is_complete(&self) -> bool { + self.state == ObjectVersionState::Complete + } + pub fn is_data(&self) -> bool { + self.state == ObjectVersionState::Complete && self.data != ObjectVersionData::DeleteMarker } } @@ -98,9 +124,7 @@ impl Entry<String, String> for Object { if other_v.size > v.size { v.size = other_v.size; } - if other_v.is_complete && !v.is_complete { - v.is_complete = true; - } + v.state = v.state.max(other_v.state); } Err(i) => { self.versions.insert(i, other_v.clone()); @@ -112,7 +136,7 @@ impl Entry<String, String> for Object { .iter() .enumerate() .rev() - .filter(|(_, v)| v.is_complete) + .filter(|(_, v)| v.is_complete()) .next() .map(|(vi, _)| vi); @@ -159,9 +183,6 @@ impl TableSchema for ObjectTable { } fn matches_filter(entry: &Self::E, _filter: &Self::Filter) -> bool { - entry - .versions - .iter() - .any(|x| x.is_complete && x.data != ObjectVersionData::DeleteMarker) + entry.versions.iter().any(|v| v.is_data()) } } diff --git a/src/core/version_table.rs b/src/core/version_table.rs index ae32e5cb..cd4448ad 100644 --- a/src/core/version_table.rs +++ b/src/core/version_table.rs @@ -64,6 +64,7 @@ impl Version { #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct VersionBlock { + pub part_number: u64, pub offset: u64, pub hash: Hash, } |