From 64ac31668dfd89c9e700d683d8f4c1aae1728703 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 24 Oct 2023 19:22:02 +0400 Subject: Remove time crate in favor of manual impl Cuts down a few more dependencies. --- Cargo.lock | 62 ------------------------------------------------------------ Cargo.toml | 1 - src/utils.rs | 32 +++++++++++++++++++++---------- 3 files changed, 22 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 043d3a1f..45e0599d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -696,15 +696,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf" -[[package]] -name = "deranged" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" -dependencies = [ - "powerfmt", -] - [[package]] name = "derivative" version = "2.2.0" @@ -1170,12 +1161,6 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bffb4def18c48926ccac55c1223e02865ce1a821751a95920448662696e7472c" -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - [[package]] name = "jni" version = "0.21.1" @@ -1548,7 +1533,6 @@ dependencies = [ "serde", "smithay", "smithay-drm-extras", - "time", "tracing", "tracing-subscriber", "tracy-client", @@ -1631,15 +1615,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - [[package]] name = "objc-sys" version = "0.3.1" @@ -1823,12 +1798,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023" -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2447,37 +2416,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" -dependencies = [ - "deranged", - "itoa", - "libc", - "num_threads", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" -dependencies = [ - "time-core", -] - [[package]] name = "toml" version = "0.8.4" diff --git a/Cargo.toml b/Cargo.toml index a3704ed6..1f228785 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ portable-atomic = { version = "1.5.0", default-features = false, features = ["fl profiling = "1.0.11" sd-notify = "0.4.1" serde = { version = "1.0.189", features = ["derive"] } -time = { version = "0.3.30", features = ["formatting", "local-offset", "macros"] } tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] } tracy-client = { version = "0.16.3", default-features = false } diff --git a/src/utils.rs b/src/utils.rs index 80f5a0a1..134112dc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,15 +1,16 @@ use std::ffi::OsStr; use std::io::{self, Write}; +use std::os::unix::prelude::OsStrExt; use std::os::unix::process::CommandExt; use std::path::PathBuf; use std::process::{Command, Stdio}; +use std::ptr::null_mut; use std::time::Duration; -use anyhow::Context; +use anyhow::{ensure, Context}; use directories::UserDirs; use smithay::reexports::rustix::time::{clock_gettime, ClockId}; use smithay::utils::{Logical, Point, Rectangle}; -use time::OffsetDateTime; pub fn get_monotonic_time() -> Duration { let ts = clock_gettime(ClockId::Monotonic); @@ -29,16 +30,27 @@ pub fn make_screenshot_path() -> anyhow::Result { }); path.push("Screenshots"); + let mut buf = [0u8; 256]; + let name; unsafe { - // are you kidding me - time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound); - }; + let time = libc::time(null_mut()); + ensure!(time != -1, "error in time()"); + + let tm = libc::localtime(&time); + ensure!(!tm.is_null(), "error in localtime()"); + + let format = b"Screenshot from %Y-%m-%d %H-%M-%S.png\0"; + let rv = libc::strftime( + buf.as_mut_ptr().cast(), + buf.len(), + format.as_ptr().cast(), + tm, + ); + ensure!(rv != 0, "error formatting time"); + + name = OsStr::from_bytes(&buf[..rv]); + } - let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()); - let desc = time::macros::format_description!( - "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png" - ); - let name = now.format(desc).context("error formatting time")?; path.push(name); Ok(path) -- cgit