diff options
author | initard <solo@softwareag.com> | 2022-05-20 15:51:19 +0100 |
---|---|---|
committer | initard <solo@softwareag.com> | 2022-05-20 16:09:23 +0100 |
commit | c325c533aa6c05f73b26f8d8569b199b81b84edf (patch) | |
tree | 083137ff8fc03e6387e1a6914b753b984bf36ebb /crates/core | |
parent | bcf887cb468c04271bf38e06a904da5e615f382e (diff) |
logs are read in reverse and use modified date
- logs are now read in reverse order into a VecDeque
- log files now use metadata for modified time
Signed-off-by: initard <solo@softwareag.com>
Diffstat (limited to 'crates/core')
-rw-r--r-- | crates/core/c8y_smartrest/src/smartrest_deserializer.rs | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs index 0d2fb0c5..54e96855 100644 --- a/crates/core/c8y_smartrest/src/smartrest_deserializer.rs +++ b/crates/core/c8y_smartrest/src/smartrest_deserializer.rs @@ -5,7 +5,6 @@ use download::DownloadInfo; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize}; use std::convert::{TryFrom, TryInto}; -use std::path::Path; use time::{format_description, OffsetDateTime}; #[derive(Debug)] @@ -294,48 +293,12 @@ impl SmartRestJwtResponse { } } -/// Returns a date time object from a file path or file-path-like string -/// a typical file stem looks like this: "software-list-2021-10-27T10:29:58Z" -/// -/// # Examples: -/// ``` -/// use std::path::PathBuf; -/// use crate::c8y_smartrest::smartrest_deserializer::get_datetime_from_file_path; -/// -/// let mut path = PathBuf::new(); -/// path.push("/path/to/file/with/date/in/path-2021-10-27T10:29:58Z"); -/// let path_bufdate_time = get_datetime_from_file_path(&path).unwrap(); -/// ``` -pub fn get_datetime_from_file_path(log_path: &Path) -> Option<OffsetDateTime> { - if let Some(stem_string) = log_path.file_stem().and_then(|s| s.to_str()) { - // a typical file stem looks like this: software-list-2021-10-27T10:29:58Z. - // to extract the date, rsplit string on "-" and take (last) 3 - let mut stem_string_vec = stem_string.rsplit('-').take(3).collect::<Vec<_>>(); - // reverse back the order (because of rsplit) - stem_string_vec.reverse(); - // join on '-' to get the date string - let date_string = stem_string_vec.join("-"); - let dt = OffsetDateTime::parse(&date_string, &format_description::well_known::Rfc3339); - match dt { - Ok(dt) => { - return Some(dt); - } - Err(_) => { - return None; - } - } - } - None -} - #[cfg(test)] mod tests { use super::*; use agent_interface::*; use assert_json_diff::*; use serde_json::json; - use std::path::PathBuf; - use std::str::FromStr; use test_case::test_case; // To avoid using an ID randomly generated, which is not convenient for testing. @@ -639,28 +602,4 @@ mod tests { }; assert_eq!(request, expected_output); } - - #[test_case("/path/to/software-list-2021-10-27T10:44:44Z.log")] - #[test_case("/path/to/tedge/agent/software-update-2021-10-25T07:45:41Z.log")] - #[test_case("/path/to/another-variant-2021-10-25T07:45:41Z.log")] - #[test_case("/yet-another-variant-2021-10-25T07:45:41Z.log")] - fn test_datetime_parsing_from_path(file_path: &str) { - // checking that `get_date_from_file_path` unwraps a `chrono::NaiveDateTime` object. - // this should return an Ok Result. - let path_buf = PathBuf::from_str(file_path).unwrap(); - let path_buf_datetime = get_datetime_from_file_path(&path_buf); - assert!(path_buf_datetime.is_some()); - } - - #[test_case("/path/to/software-list-2021-10-27-10:44:44Z.log")] - #[test_case("/path/to/tedge/agent/software-update-10-25-2021T07:45:41Z.log")] - #[test_case("/path/to/another-variant-07:45:41Z-2021-10-25T.log")] - #[test_case("/yet-another-variant-2021-10-25T07:45Z.log")] - fn test_datetime_parsing_from_path_fail(file_path: &str) { - // checking that `get_date_from_file_path` unwraps a `chrono::NaiveDateTime` object. - // this should return an err. - let path_buf = PathBuf::from_str(file_path).unwrap(); - let path_buf_datetime = get_datetime_from_file_path(&path_buf); - assert!(path_buf_datetime.is_none()); - } } |