Skip to content

Commit 9698500

Browse files
committed
Move try_deserialize_timestamp to bootc_utils
Signed-off-by: Etienne Champetier <[email protected]>
1 parent c582017 commit 9698500

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl InstallAleph {
535535
l.get(oci_spec::image::ANNOTATION_CREATED)
536536
.map(|s| s.as_str())
537537
})
538-
.and_then(crate::status::try_deserialize_timestamp);
538+
.and_then(bootc_utils::try_deserialize_timestamp);
539539
let r = InstallAleph {
540540
image: src_imageref.imgref.name.clone(),
541541
version: imgstate.version().as_ref().map(|s| s.to_string()),

lib/src/status.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ pub(crate) struct Deployments {
102102
pub(crate) other: VecDeque<ostree::Deployment>,
103103
}
104104

105-
pub(crate) fn try_deserialize_timestamp(t: &str) -> Option<chrono::DateTime<chrono::Utc>> {
106-
match chrono::DateTime::parse_from_rfc3339(t).context("Parsing timestamp") {
107-
Ok(t) => Some(t.into()),
108-
Err(e) => {
109-
tracing::warn!("Invalid timestamp in image: {:#}", e);
110-
None
111-
}
112-
}
113-
}
114-
115105
pub(crate) fn labels_of_config(
116106
config: &oci_spec::image::ImageConfiguration,
117107
) -> Option<&std::collections::HashMap<String, String>> {

lib/src/store/ostree_container.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Context, Result};
1+
use anyhow::Result;
22

33
use ostree_ext::container as ostree_container;
44
use ostree_ext::oci_spec;
@@ -52,7 +52,7 @@ fn create_imagestatus(
5252
.map(|s| s.as_str())
5353
})
5454
.or_else(|| config.created().as_deref())
55-
.and_then(try_deserialize_timestamp);
55+
.and_then(bootc_utils::try_deserialize_timestamp);
5656

5757
let version = ostree_container::version_for_config(config).map(ToOwned::to_owned);
5858
let architecture = config.architecture().to_string();
@@ -70,13 +70,3 @@ fn labels_of_config(
7070
) -> Option<&std::collections::HashMap<String, String>> {
7171
config.config().as_ref().and_then(|c| c.labels().as_ref())
7272
}
73-
74-
fn try_deserialize_timestamp(t: &str) -> Option<chrono::DateTime<chrono::Utc>> {
75-
match chrono::DateTime::parse_from_rfc3339(t).context("Parsing timestamp") {
76-
Ok(t) => Some(t.into()),
77-
Err(e) => {
78-
tracing::warn!("Invalid timestamp in image: {:#}", e);
79-
None
80-
}
81-
}
82-
}

utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/bootc-dev/bootc"
88

99
[dependencies]
1010
anyhow = { workspace = true }
11+
chrono = { workspace = true, features = ["std"] }
1112
rustix = { workspace = true }
1213
serde = { workspace = true, features = ["derive"] }
1314
serde_json = { workspace = true }

utils/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ mod path;
88
pub use path::*;
99
mod iterators;
1010
pub use iterators::*;
11+
mod timestamp;
12+
pub use timestamp::*;
1113
mod tracing_util;
1214
pub use tracing_util::*;

utils/src/timestamp.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use anyhow::Context;
2+
use chrono;
3+
4+
/// Try to parse an RFC 3339, warn on error.
5+
pub fn try_deserialize_timestamp(t: &str) -> Option<chrono::DateTime<chrono::Utc>> {
6+
match chrono::DateTime::parse_from_rfc3339(t).context("Parsing timestamp") {
7+
Ok(t) => Some(t.into()),
8+
Err(e) => {
9+
tracing::warn!("Invalid timestamp in image: {:#}", e);
10+
None
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)