|
|
@@ -1,26 +1,40 @@
|
|
|
use {
|
|
|
- super::{SnapshotKind, SnapshotPackage},
|
|
|
+ super::{SnapshotArchiveKind, SnapshotKind, SnapshotPackage},
|
|
|
std::cmp::Ordering::{self, Equal, Greater, Less},
|
|
|
};
|
|
|
|
|
|
-/// Compare snapshot packages by priority; first by type, then by slot
|
|
|
+/// Compare snapshot packages by priority; first by kind, then by slot
|
|
|
#[must_use]
|
|
|
pub fn cmp_snapshot_packages_by_priority(a: &SnapshotPackage, b: &SnapshotPackage) -> Ordering {
|
|
|
cmp_snapshot_kinds_by_priority(&a.snapshot_kind, &b.snapshot_kind).then(a.slot.cmp(&b.slot))
|
|
|
}
|
|
|
|
|
|
/// Compare snapshot kinds by priority
|
|
|
-///
|
|
|
-/// Full snapshots are higher in priority than incremental snapshots.
|
|
|
-/// If two `IncrementalSnapshot`s are compared, their base slots are the tiebreaker.
|
|
|
#[must_use]
|
|
|
pub fn cmp_snapshot_kinds_by_priority(a: &SnapshotKind, b: &SnapshotKind) -> Ordering {
|
|
|
use SnapshotKind as Kind;
|
|
|
match (a, b) {
|
|
|
- (Kind::FullSnapshot, Kind::FullSnapshot) => Equal,
|
|
|
- (Kind::FullSnapshot, Kind::IncrementalSnapshot(_)) => Greater,
|
|
|
- (Kind::IncrementalSnapshot(_), Kind::FullSnapshot) => Less,
|
|
|
- (Kind::IncrementalSnapshot(base_slot_a), Kind::IncrementalSnapshot(base_slot_b)) => {
|
|
|
+ (Kind::Archive(snapshot_archive_kind_a), Kind::Archive(snapshot_archive_kind_b)) => {
|
|
|
+ cmp_snapshot_archive_kinds_by_priority(snapshot_archive_kind_a, snapshot_archive_kind_b)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/// Compare snapshot archive kinds by priority
|
|
|
+///
|
|
|
+/// Full snapshot archives are higher in priority than incremental snapshot archives.
|
|
|
+/// If two `Incremental`s are compared, their base slots are the tiebreaker.
|
|
|
+#[must_use]
|
|
|
+pub fn cmp_snapshot_archive_kinds_by_priority(
|
|
|
+ a: &SnapshotArchiveKind,
|
|
|
+ b: &SnapshotArchiveKind,
|
|
|
+) -> Ordering {
|
|
|
+ use SnapshotArchiveKind as Kind;
|
|
|
+ match (a, b) {
|
|
|
+ (Kind::Full, Kind::Full) => Equal,
|
|
|
+ (Kind::Full, Kind::Incremental(_)) => Greater,
|
|
|
+ (Kind::Incremental(_), Kind::Full) => Less,
|
|
|
+ (Kind::Incremental(base_slot_a), Kind::Incremental(base_slot_b)) => {
|
|
|
base_slot_a.cmp(base_slot_b)
|
|
|
}
|
|
|
}
|
|
|
@@ -43,53 +57,92 @@ mod tests {
|
|
|
|
|
|
for (snapshot_package_a, snapshot_package_b, expected_result) in [
|
|
|
(
|
|
|
- new(SnapshotKind::FullSnapshot, 11),
|
|
|
- new(SnapshotKind::FullSnapshot, 22),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 11),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 22),
|
|
|
Less,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::FullSnapshot, 22),
|
|
|
- new(SnapshotKind::FullSnapshot, 22),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 22),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 22),
|
|
|
Equal,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::FullSnapshot, 33),
|
|
|
- new(SnapshotKind::FullSnapshot, 22),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 33),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 22),
|
|
|
Greater,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::FullSnapshot, 22),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(88), 99),
|
|
|
+ new(SnapshotKind::Archive(SnapshotArchiveKind::Full), 22),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(88)),
|
|
|
+ 99,
|
|
|
+ ),
|
|
|
Greater,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(11), 55),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(11)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Less,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Equal,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(33), 55),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(33)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Greater,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 44),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 44,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Less,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Equal,
|
|
|
),
|
|
|
(
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 66),
|
|
|
- new(SnapshotKind::IncrementalSnapshot(22), 55),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 66,
|
|
|
+ ),
|
|
|
+ new(
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(22)),
|
|
|
+ 55,
|
|
|
+ ),
|
|
|
Greater,
|
|
|
),
|
|
|
] {
|
|
|
@@ -103,33 +156,33 @@ mod tests {
|
|
|
fn test_cmp_snapshot_kinds_by_priority() {
|
|
|
for (snapshot_kind_a, snapshot_kind_b, expected_result) in [
|
|
|
(
|
|
|
- SnapshotKind::FullSnapshot,
|
|
|
- SnapshotKind::FullSnapshot,
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Full),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Full),
|
|
|
Equal,
|
|
|
),
|
|
|
(
|
|
|
- SnapshotKind::FullSnapshot,
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Full),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
Greater,
|
|
|
),
|
|
|
(
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
- SnapshotKind::FullSnapshot,
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Full),
|
|
|
Less,
|
|
|
),
|
|
|
(
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
- SnapshotKind::IncrementalSnapshot(6),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(6)),
|
|
|
Less,
|
|
|
),
|
|
|
(
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
Equal,
|
|
|
),
|
|
|
(
|
|
|
- SnapshotKind::IncrementalSnapshot(5),
|
|
|
- SnapshotKind::IncrementalSnapshot(4),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(5)),
|
|
|
+ SnapshotKind::Archive(SnapshotArchiveKind::Incremental(4)),
|
|
|
Greater,
|
|
|
),
|
|
|
] {
|
|
|
@@ -137,4 +190,42 @@ mod tests {
|
|
|
assert_eq!(expected_result, actual_result);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn test_cmp_snapshot_archive_kinds_by_priority() {
|
|
|
+ for (snapshot_archive_kind_a, snapshot_archive_kind_b, expected_result) in [
|
|
|
+ (SnapshotArchiveKind::Full, SnapshotArchiveKind::Full, Equal),
|
|
|
+ (
|
|
|
+ SnapshotArchiveKind::Full,
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ Greater,
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ SnapshotArchiveKind::Full,
|
|
|
+ Less,
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ SnapshotArchiveKind::Incremental(6),
|
|
|
+ Less,
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ Equal,
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ SnapshotArchiveKind::Incremental(5),
|
|
|
+ SnapshotArchiveKind::Incremental(4),
|
|
|
+ Greater,
|
|
|
+ ),
|
|
|
+ ] {
|
|
|
+ let actual_result = cmp_snapshot_archive_kinds_by_priority(
|
|
|
+ &snapshot_archive_kind_a,
|
|
|
+ &snapshot_archive_kind_b,
|
|
|
+ );
|
|
|
+ assert_eq!(expected_result, actual_result);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|