forge
Explore
Log in

Don't you dare go Hollow

Remove time crate in favor of manual impl

Browse files at this commit

64ac31668dfd89c9e700d683d8f4c1aae1728703Ivan MolodetskikhParent: 909a45d
Cuts down a few more dependencies.
Cargo.lockmodified+0 -62
@@ -696,15 +696,6 @@ version = "1.0.0"
696 source = "registry+https://github.com/rust-lang/crates.io-index"696 source = "registry+https://github.com/rust-lang/crates.io-index"
697 checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"697 checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
698 698
699-[[package]]
700-name = "deranged"
701-version = "0.3.9"
702-source = "registry+https://github.com/rust-lang/crates.io-index"
703-checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
704-dependencies = [
705- "powerfmt",
706-]
707-
708 [[package]]699 [[package]]
709 name = "derivative"700 name = "derivative"
710 version = "2.2.0"701 version = "2.2.0"
@@ -1170,12 +1161,6 @@ version = "2.0.2"
1170 source = "registry+https://github.com/rust-lang/crates.io-index"1161 source = "registry+https://github.com/rust-lang/crates.io-index"
1171 checksum = "bffb4def18c48926ccac55c1223e02865ce1a821751a95920448662696e7472c"1162 checksum = "bffb4def18c48926ccac55c1223e02865ce1a821751a95920448662696e7472c"
1172 1163
1173-[[package]]
1174-name = "itoa"
1175-version = "1.0.9"
1176-source = "registry+https://github.com/rust-lang/crates.io-index"
1177-checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
1178-
1179 [[package]]1164 [[package]]
1180 name = "jni"1165 name = "jni"
1181 version = "0.21.1"1166 version = "0.21.1"
@@ -1548,7 +1533,6 @@ dependencies = [
1548 "serde",1533 "serde",
1549 "smithay",1534 "smithay",
1550 "smithay-drm-extras",1535 "smithay-drm-extras",
1551- "time",
1552 "tracing",1536 "tracing",
1553 "tracing-subscriber",1537 "tracing-subscriber",
1554 "tracy-client",1538 "tracy-client",
@@ -1631,15 +1615,6 @@ dependencies = [
1631 "syn 2.0.38",1615 "syn 2.0.38",
1632 ]1616 ]
1633 1617
1634-[[package]]
1635-name = "num_threads"
1636-version = "0.1.6"
1637-source = "registry+https://github.com/rust-lang/crates.io-index"
1638-checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
1639-dependencies = [
1640- "libc",
1641-]
1642-
1643 [[package]]1618 [[package]]
1644 name = "objc-sys"1619 name = "objc-sys"
1645 version = "0.3.1"1620 version = "0.3.1"
@@ -1823,12 +1798,6 @@ version = "1.5.0"
1823 source = "registry+https://github.com/rust-lang/crates.io-index"1798 source = "registry+https://github.com/rust-lang/crates.io-index"
1824 checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023"1799 checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023"
1825 1800
1826-[[package]]
1827-name = "powerfmt"
1828-version = "0.2.0"
1829-source = "registry+https://github.com/rust-lang/crates.io-index"
1830-checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1831-
1832 [[package]]1801 [[package]]
1833 name = "ppv-lite86"1802 name = "ppv-lite86"
1834 version = "0.2.17"1803 version = "0.2.17"
@@ -2447,37 +2416,6 @@ dependencies = [
2447 "once_cell",2416 "once_cell",
2448 ]2417 ]
2449 2418
2450-[[package]]
2451-name = "time"
2452-version = "0.3.30"
2453-source = "registry+https://github.com/rust-lang/crates.io-index"
2454-checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
2455-dependencies = [
2456- "deranged",
2457- "itoa",
2458- "libc",
2459- "num_threads",
2460- "powerfmt",
2461- "serde",
2462- "time-core",
2463- "time-macros",
2464-]
2465-
2466-[[package]]
2467-name = "time-core"
2468-version = "0.1.2"
2469-source = "registry+https://github.com/rust-lang/crates.io-index"
2470-checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
2471-
2472-[[package]]
2473-name = "time-macros"
2474-version = "0.2.15"
2475-source = "registry+https://github.com/rust-lang/crates.io-index"
2476-checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
2477-dependencies = [
2478- "time-core",
2479-]
2480-
2481 [[package]]2419 [[package]]
2482 name = "toml"2420 name = "toml"
2483 version = "0.8.4"2421 version = "0.8.4"
Cargo.tomlmodified+0 -1
@@ -26,7 +26,6 @@ portable-atomic = { version = "1.5.0", default-features = false, features = ["fl
26 profiling = "1.0.11"26 profiling = "1.0.11"
27 sd-notify = "0.4.1"27 sd-notify = "0.4.1"
28 serde = { version = "1.0.189", features = ["derive"] }28 serde = { version = "1.0.189", features = ["derive"] }
29-time = { version = "0.3.30", features = ["formatting", "local-offset", "macros"] }
30 tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }29 tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
31 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }30 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
32 tracy-client = { version = "0.16.3", default-features = false }31 tracy-client = { version = "0.16.3", default-features = false }
src/utils.rsmodified+22 -10
@@ -1,15 +1,16 @@
1 use std::ffi::OsStr;1 use std::ffi::OsStr;
2 use std::io::{self, Write};2 use std::io::{self, Write};
3+use std::os::unix::prelude::OsStrExt;
3 use std::os::unix::process::CommandExt;4 use std::os::unix::process::CommandExt;
4 use std::path::PathBuf;5 use std::path::PathBuf;
5 use std::process::{Command, Stdio};6 use std::process::{Command, Stdio};
7+use std::ptr::null_mut;
6 use std::time::Duration;8 use std::time::Duration;
7 9
8-use anyhow::Context;10+use anyhow::{ensure, Context};
9 use directories::UserDirs;11 use directories::UserDirs;
10 use smithay::reexports::rustix::time::{clock_gettime, ClockId};12 use smithay::reexports::rustix::time::{clock_gettime, ClockId};
11 use smithay::utils::{Logical, Point, Rectangle};13 use smithay::utils::{Logical, Point, Rectangle};
12-use time::OffsetDateTime;
13 14
14 pub fn get_monotonic_time() -> Duration {15 pub fn get_monotonic_time() -> Duration {
15 let ts = clock_gettime(ClockId::Monotonic);16 let ts = clock_gettime(ClockId::Monotonic);
@@ -29,16 +30,27 @@ pub fn make_screenshot_path() -> anyhow::Result<PathBuf> {
29 });30 });
30 path.push("Screenshots");31 path.push("Screenshots");
31 32
33+ let mut buf = [0u8; 256];
34+ let name;
32 unsafe {35 unsafe {
33- // are you kidding me36+ let time = libc::time(null_mut());
34- time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);37+ ensure!(time != -1, "error in time()");
35- };38+
39+ let tm = libc::localtime(&time);
40+ ensure!(!tm.is_null(), "error in localtime()");
41+
42+ let format = b"Screenshot from %Y-%m-%d %H-%M-%S.png\0";
43+ let rv = libc::strftime(
44+ buf.as_mut_ptr().cast(),
45+ buf.len(),
46+ format.as_ptr().cast(),
47+ tm,
48+ );
49+ ensure!(rv != 0, "error formatting time");
50+
51+ name = OsStr::from_bytes(&buf[..rv]);
52+ }
36 53
37- let now = OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc());
38- let desc = time::macros::format_description!(
39- "Screenshot from [year]-[month]-[day] [hour]-[minute]-[second].png"
40- );
41- let name = now.format(desc).context("error formatting time")?;
42 path.push(name);54 path.push(name);
43 55
44 Ok(path)56 Ok(path)