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"
696696 source = "registry+https://github.com/rust-lang/crates.io-index"
697697 checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
698698
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-
708699 [[package]]
709700 name = "derivative"
710701 version = "2.2.0"
@@ -1170,12 +1161,6 @@ version = "2.0.2"
11701161 source = "registry+https://github.com/rust-lang/crates.io-index"
11711162 checksum = "bffb4def18c48926ccac55c1223e02865ce1a821751a95920448662696e7472c"
11721163
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-
11791164 [[package]]
11801165 name = "jni"
11811166 version = "0.21.1"
@@ -1548,7 +1533,6 @@ dependencies = [
15481533 "serde",
15491534 "smithay",
15501535 "smithay-drm-extras",
1551- "time",
15521536 "tracing",
15531537 "tracing-subscriber",
15541538 "tracy-client",
@@ -1631,15 +1615,6 @@ dependencies = [
16311615 "syn 2.0.38",
16321616 ]
16331617
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-
16431618 [[package]]
16441619 name = "objc-sys"
16451620 version = "0.3.1"
@@ -1823,12 +1798,6 @@ version = "1.5.0"
18231798 source = "registry+https://github.com/rust-lang/crates.io-index"
18241799 checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023"
18251800
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-
18321801 [[package]]
18331802 name = "ppv-lite86"
18341803 version = "0.2.17"
@@ -2447,37 +2416,6 @@ dependencies = [
24472416 "once_cell",
24482417 ]
24492418
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-
24812419 [[package]]
24822420 name = "toml"
24832421 version = "0.8.4"
Cargo.tomlmodified+0 -1
@@ -26,7 +26,6 @@ portable-atomic = { version = "1.5.0", default-features = false, features = ["fl
2626 profiling = "1.0.11"
2727 sd-notify = "0.4.1"
2828 serde = { version = "1.0.189", features = ["derive"] }
29-time = { version = "0.3.30", features = ["formatting", "local-offset", "macros"] }
3029 tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
3130 tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
3231 tracy-client = { version = "0.16.3", default-features = false }
src/utils.rsmodified+22 -10
@@ -1,15 +1,16 @@
11 use std::ffi::OsStr;
22 use std::io::{self, Write};
3+use std::os::unix::prelude::OsStrExt;
34 use std::os::unix::process::CommandExt;
45 use std::path::PathBuf;
56 use std::process::{Command, Stdio};
7+use std::ptr::null_mut;
68 use std::time::Duration;
79
8-use anyhow::Context;
10+use anyhow::{ensure, Context};
911 use directories::UserDirs;
1012 use smithay::reexports::rustix::time::{clock_gettime, ClockId};
1113 use smithay::utils::{Logical, Point, Rectangle};
12-use time::OffsetDateTime;
1314
1415 pub fn get_monotonic_time() -> Duration {
1516 let ts = clock_gettime(ClockId::Monotonic);
@@ -29,16 +30,27 @@ pub fn make_screenshot_path() -> anyhow::Result<PathBuf> {
2930 });
3031 path.push("Screenshots");
3132
33+ let mut buf = [0u8; 256];
34+ let name;
3235 unsafe {
33- // are you kidding me
34- time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);
35- };
36+ let time = libc::time(null_mut());
37+ ensure!(time != -1, "error in time()");
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+ }
3653
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")?;
4254 path.push(name);
4355
4456 Ok(path)