From 9609e8a22a71a1ad56387b59a30704a4adb21258 Mon Sep 17 00:00:00 2001 From: micwoj92 <45581170+micwoj92@users.noreply.github.com> Date: Thu, 21 Mar 2024 20:43:24 +0100 Subject: [PATCH 1/2] Update to latest chrono --- Cargo.lock | 89 +++++++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 2 +- 2 files changed, 65 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 109e760..4537d8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,18 +352,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.28" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "serde", - "time 0.1.45", "wasm-bindgen", - "windows-targets", + "windows-targets 0.52.4", ] [[package]] @@ -826,7 +825,7 @@ checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -1059,7 +1058,7 @@ dependencies = [ "dirs-next", "objc-foundation", "objc_id", - "time 0.3.28", + "time", ] [[package]] @@ -1711,17 +1710,6 @@ dependencies = [ "syn 2.0.31", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.28" @@ -1881,12 +1869,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2026,7 +2008,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2050,7 +2032,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -2068,6 +2050,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -2080,6 +2077,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.39.0" @@ -2098,6 +2101,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_gen" version = "0.10.0" @@ -2122,6 +2131,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.39.0" @@ -2140,6 +2155,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_macros" version = "0.10.0" @@ -2168,6 +2189,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -2180,6 +2207,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.39.0" @@ -2198,6 +2231,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "winnow" version = "0.5.15" diff --git a/Cargo.toml b/Cargo.toml index 3d63bca..d001fcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" [dependencies] anyhow = "1.0.40" atoi = "2" -chrono = { version = "0.4.19", features = ["serde"] } +chrono = { version = "0.4.35", features = ["serde"] } chrono-humanize = "0.2.1" clamav-rs = { git = "https://github.com/kpcyrd/clamav-rs", branch = "clamav-1.2" } clap = { version = "4.0.32", features = ["derive"] } From e8d864365f2c95709de55201304d851b7b4bcb8b Mon Sep 17 00:00:00 2001 From: micwoj92 <45581170+micwoj92@users.noreply.github.com> Date: Thu, 21 Mar 2024 20:43:50 +0100 Subject: [PATCH 2/2] Fix deprecation warnings --- src/schedule.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/schedule.rs b/src/schedule.rs index 91146e4..cac6c85 100644 --- a/src/schedule.rs +++ b/src/schedule.rs @@ -50,7 +50,7 @@ impl PreferedHours { ) .earliest() .unwrap() - + chrono::Duration::hours(24); + + chrono::Duration::try_hours(24).unwrap(); next_start - dt } } @@ -84,7 +84,7 @@ impl PreferedHours { ) .earliest() .unwrap() - + chrono::Duration::hours(24); + + chrono::Duration::try_hours(24).unwrap(); next_end - dt } } @@ -151,7 +151,7 @@ fn robust_sleep(sleep: chrono::Duration) -> Result<()> { break; } - let next_sleep = cmp::min(chrono::Duration::seconds(600), remaining); + let next_sleep = cmp::min(chrono::Duration::try_seconds(600).unwrap(), remaining); trace!("Sleeping for {:?}", next_sleep); thread::sleep(next_sleep.to_std()?); @@ -161,7 +161,7 @@ fn robust_sleep(sleep: chrono::Duration) -> Result<()> { } pub fn run(_args: &args::Scheduler) -> Result<()> { - let interval = chrono::Duration::hours(24); + let interval = chrono::Duration::try_hours(24).unwrap(); loop { let now = Local::now(); @@ -258,7 +258,7 @@ pub fn run(_args: &args::Scheduler) -> Result<()> { let preferred_hours_duration = (end - start).num_seconds(); let jitter = rng.gen_range(0..preferred_hours_duration); - start + chrono::Duration::seconds(jitter) + start + chrono::Duration::try_seconds(jitter).unwrap() }, ) } @@ -311,7 +311,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("19:00:00-09:00:00").unwrap(); let duration = ph.until_next_start(now); - assert_eq!(duration, chrono::Duration::seconds(5 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(5 * 3600 + 23 * 60).unwrap()); } #[test] @@ -322,7 +322,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("19:00:00-09:00:00").unwrap(); let duration = ph.until_next_end(now); - assert_eq!(duration, chrono::Duration::seconds(19 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(19 * 3600 + 23 * 60).unwrap()); } #[test] @@ -333,7 +333,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("19:00:00-09:00:00").unwrap(); let duration = ph.until_next_start(now); - assert_eq!(duration, chrono::Duration::seconds(0)); + assert_eq!(duration, chrono::Duration::try_seconds(0).unwrap()); } #[test] @@ -344,7 +344,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("19:00:00-09:00:00").unwrap(); let duration = ph.until_next_end(now); - assert_eq!(duration, chrono::Duration::seconds(9 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(9 * 3600 + 23 * 60).unwrap()); } #[test] @@ -355,7 +355,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("09:00:00-19:00:00").unwrap(); let duration = ph.until_next_start(now); - assert_eq!(duration, chrono::Duration::seconds(0)); + assert_eq!(duration, chrono::Duration::try_seconds(0).unwrap()); } #[test] @@ -366,7 +366,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("09:00:00-19:00:00").unwrap(); let duration = ph.until_next_end(now); - assert_eq!(duration, chrono::Duration::seconds(5 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(5 * 3600 + 23 * 60).unwrap()); } #[test] @@ -377,7 +377,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("13:37:00-23:00:00").unwrap(); let duration = ph.until_next_start(now); - assert_eq!(duration, chrono::Duration::seconds(4 * 3600 + 37 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(4 * 3600 + 37 * 60).unwrap()); } #[test] @@ -388,7 +388,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("13:37:00-23:00:00").unwrap(); let duration = ph.until_next_end(now); - assert_eq!(duration, chrono::Duration::seconds(14 * 3600)); + assert_eq!(duration, chrono::Duration::try_seconds(14 * 3600).unwrap()); } #[test] @@ -399,7 +399,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("4:00:00-9:00:00").unwrap(); let duration = ph.until_next_start(now); - assert_eq!(duration, chrono::Duration::seconds(14 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(14 * 3600 + 23 * 60).unwrap()); } #[test] @@ -410,7 +410,7 @@ mod tests { .unwrap(); let ph = PreferedHours::from_str("4:00:00-9:00:00").unwrap(); let duration = ph.until_next_end(now); - assert_eq!(duration, chrono::Duration::seconds(19 * 3600 + 23 * 60)); + assert_eq!(duration, chrono::Duration::try_seconds(19 * 3600 + 23 * 60).unwrap()); } #[test]