Skip to content

Commit

Permalink
Missed a thing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Jan 10, 2025
1 parent cbdc1e5 commit b5dd587
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/inventory/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::keypath::KeyPath;
use crate::s3::S3Location;
use crate::util::make_old_filename;
use time::OffsetDateTime;

/// An entry in an inventory list file
Expand Down Expand Up @@ -75,6 +76,14 @@ impl InventoryItem {
pub(crate) fn is_deleted(&self) -> bool {
self.details == ItemDetails::Deleted
}

Check warning on line 78 in src/inventory/item.rs

View check run for this annotation

Codecov / codecov/patch

src/inventory/item.rs#L76-L78

Added lines #L76 - L78 were not covered by tests

pub(crate) fn old_filename(&self) -> Option<String> {
let ItemDetails::Present { ref etag, .. } = self.details else {
return None;

Check warning on line 82 in src/inventory/item.rs

View check run for this annotation

Codecov / codecov/patch

src/inventory/item.rs#L80-L82

Added lines #L80 - L82 were not covered by tests
};
(!self.is_deleted() && !self.is_latest)
.then(|| make_old_filename(self.key.name(), &self.version_id, etag))
}

Check warning on line 86 in src/inventory/item.rs

View check run for this annotation

Codecov / codecov/patch

src/inventory/item.rs#L84-L86

Added lines #L84 - L86 were not covered by tests
}

/// Metadata about an object's content
Expand Down
7 changes: 7 additions & 0 deletions src/keypath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ use thiserror::Error;
pub(crate) struct KeyPath(String);

impl KeyPath {
pub(crate) fn name(&self) -> &str {
self.0
.split('/')
.next_back()
.expect("path should be nonempty")
}

Check warning on line 23 in src/keypath.rs

View check run for this annotation

Codecov / codecov/patch

src/keypath.rs#L18-L23

Added lines #L18 - L23 were not covered by tests

/// Split the path into the directory component (if any) and filename
pub(crate) fn split(&self) -> (Option<&str>, &str) {
match self.0.rsplit_once('/') {
Expand Down
3 changes: 2 additions & 1 deletion src/syncer/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::util::make_old_filename;
use serde::{Deserialize, Serialize};
use std::io::ErrorKind;

Expand All @@ -17,7 +18,7 @@ impl Metadata {
/// `self` as its metadata and `basename` as the filename portion of its
/// key
pub(super) fn old_filename(&self, basename: &str) -> String {
format!("{}.old.{}.{}", basename, self.version_id, self.etag)
make_old_filename(basename, &self.version_id, &self.etag)
}

Check warning on line 22 in src/syncer/metadata.rs

View check run for this annotation

Codecov / codecov/patch

src/syncer/metadata.rs#L20-L22

Added lines #L20 - L22 were not covered by tests
}

Expand Down
2 changes: 1 addition & 1 deletion src/syncer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Syncer {
InventoryEntry::Item(item) => {
let notify = if !item.is_deleted() {
let notify = Arc::new(Notify::new());
for dir in tracker.add(&item.key, notify.clone(), None)? {
for dir in tracker.add(&item.key, notify.clone(), item.old_filename())? {
subnursery.spawn({
this.until_cancelled_ok({
let this = this.clone();
Expand Down
4 changes: 4 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pub(crate) fn force_create_dir_all<I: IntoIterator<Item: AsRef<Path>>>(
Ok(())
}

pub(crate) fn make_old_filename(basename: &str, version_id: &str, etag: &str) -> String {
format!("{basename}.old.{version_id}.{etag}")
}

Check warning on line 118 in src/util.rs

View check run for this annotation

Codecov / codecov/patch

src/util.rs#L116-L118

Added lines #L116 - L118 were not covered by tests

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit b5dd587

Please sign in to comment.