From b0fe88c2f0318a556e537e4054a5e34e681aa69c Mon Sep 17 00:00:00 2001 From: Md Isfarul Haque Date: Wed, 27 Mar 2024 13:57:22 +0530 Subject: [PATCH] [feat] use clap Derive API to accept command line arguments (#247) * [feat] Use clap derive API to parse CLI arguments This patch removes the usage of clap::Command and arg macros, and bumps the library version to use the new derive API which is the recommended method upstream. Signed-off-by: innocentzero * [feat] Use clap derive API to parse CLI arguments This patch follows the previous one to update the method of taking arguments for swhks. The derive API is the recommended method upstream. Signed-off-by: innocentzero * [fix] separate default cooldown to a separate variable Signed-off-by: innocentzero * [fix]: conflicting short options in swhkd This patch fixes the conflicting short options in swhkd and implements alternative short option forms. Signed-off-by: innocentzero * [fix] Swap short options for config and cooldown This change is meant to make the changes backwards compatible for the user. Signed-off-by: innocentzero * [fix] Apply env refactoring to swhkd Signed-off-by: innocentzero --------- Signed-off-by: innocentzero --- Cargo.lock | 239 ++++++++++++++++++++++++++++++++++---------- swhkd/Cargo.toml | 4 +- swhkd/src/daemon.rs | 77 ++++++-------- swhks/Cargo.toml | 4 +- swhks/src/main.rs | 37 +++---- 5 files changed, 240 insertions(+), 121 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9df464b..7c58ee0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "atty" version = "0.2.14" @@ -91,28 +139,50 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.23" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ - "atty", - "bitflags", + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap", "strsim", - "termcolor", - "textwrap", ] [[package]] -name = "clap_lex" -version = "0.2.4" +name = "clap_derive" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ - "os_str_bytes", + "heck", + "proc-macro2", + "quote", + "syn 2.0.52", ] +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -228,10 +298,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] -name = "hashbrown" -version = "0.12.3" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -248,16 +318,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "itertools" version = "0.10.5" @@ -344,7 +404,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -385,12 +445,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" -[[package]] -name = "os_str_bytes" -version = "6.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" - [[package]] name = "parking_lot" version = "0.12.1" @@ -411,7 +465,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -428,18 +482,18 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -553,9 +607,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "swhks" @@ -579,6 +633,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sysinfo" version = "0.23.13" @@ -609,12 +674,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.38" @@ -632,7 +691,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -652,7 +711,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -663,7 +722,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -705,6 +764,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -748,13 +813,37 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.0", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm 0.42.0", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[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]] @@ -763,42 +852,84 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[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.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[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.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +[[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.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[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.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "wyz" version = "0.5.1" diff --git a/swhkd/Cargo.toml b/swhkd/Cargo.toml index ed1b8b0..d9fc31e 100644 --- a/swhkd/Cargo.toml +++ b/swhkd/Cargo.toml @@ -6,14 +6,14 @@ version = "1.3.0-dev" authors = [ "Shinyzenith \n", "Angelo Fallaria \n", - "EdenQwQ \n" + "EdenQwQ \n", ] [build-dependencies] flate2 = "1.0.24" [dependencies] -clap = "3.1.6" +clap = { version = "4.1.0", features = ["derive"] } env_logger = "0.9.0" evdev = { version = "0.12.0", features = ["tokio"] } itertools = "0.10.3" diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index 708277b..eab40e8 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -1,5 +1,5 @@ use crate::config::Value; -use clap::{arg, Command}; +use clap::Parser; use evdev::{AttributeSet, Device, InputEventKind, Key}; use nix::{ sys::stat::{umask, Mode}, @@ -44,12 +44,34 @@ impl KeyboardState { } } +/// Simple Wayland Hotkey Daemon +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + /// Set a custom config file path. + #[arg(short = 'c', long, value_name = "FILE")] + config: Option, + + /// Set a custom repeat cooldown duration. Default is 250ms. + #[arg(short = 'C', long)] + cooldown: Option, + + /// Enable Debug Mode + #[arg(short, long)] + debug: bool, + + /// Take a list of devices from the user + #[arg(short = 'D', long, num_args = 0.., value_delimiter = ' ')] + device: Vec, +} + #[tokio::main] async fn main() -> Result<(), Box> { - let args = set_command_line_args().get_matches(); + let args = Args::parse(); + let default_cooldown: u64 = 250; env::set_var("RUST_LOG", "swhkd=warn"); - if args.is_present("debug") { + if args.debug { env::set_var("RUST_LOG", "swhkd=trace"); } @@ -67,11 +89,8 @@ async fn main() -> Result<(), Box> { // Drop privileges to the invoking user. perms::drop_privileges(invoking_uid); - let config_file_path: PathBuf = if args.is_present("config") { - Path::new(args.value_of("config").unwrap()).to_path_buf() - } else { - env.fetch_xdg_config_path() - }; + let config_file_path: PathBuf = + args.config.as_ref().map_or_else(|| env.fetch_xdg_config_path(), |file| file.clone()); log::debug!("Using config file path: {:#?}", config_file_path); @@ -136,7 +155,7 @@ async fn main() -> Result<(), Box> { }; } - let arg_devices: Vec<&str> = args.values_of("device").unwrap_or_default().collect(); + let arg_devices: Vec = args.device; let keyboard_devices: Vec<_> = { if arg_devices.is_empty() { @@ -144,7 +163,7 @@ async fn main() -> Result<(), Box> { evdev::enumerate().filter(|(_, dev)| check_device_is_keyboard(dev)).collect() } else { evdev::enumerate() - .filter(|(_, dev)| arg_devices.contains(&dev.name().unwrap_or(""))) + .filter(|(_, dev)| arg_devices.contains(&dev.name().unwrap_or("").to_string())) .collect() } }; @@ -190,11 +209,7 @@ async fn main() -> Result<(), Box> { (Key::KEY_RIGHTSHIFT, config::Modifier::Shift), ]); - let repeat_cooldown_duration: u64 = if args.is_present("cooldown") { - args.value_of("cooldown").unwrap().parse::().unwrap() - } else { - 250 - }; + let repeat_cooldown_duration: u64 = args.cooldown.unwrap_or(default_cooldown); let mut signals = Signals::new([ SIGUSR1, SIGUSR2, SIGHUP, SIGABRT, SIGBUS, SIGCHLD, SIGCONT, SIGINT, SIGPIPE, SIGQUIT, @@ -301,7 +316,7 @@ async fn main() -> Result<(), Box> { }, Ok(device) => device }; - let name = device.name().unwrap_or("[unknown]"); + let name = device.name().unwrap_or("[unknown]").to_string(); if arg_devices.contains(&name) || check_device_is_keyboard(&device) { log::info!("Device '{}' at '{}' added.", name, node); let _ = device.grab(); @@ -464,36 +479,6 @@ pub fn check_device_is_keyboard(device: &Device) -> bool { } } -pub fn set_command_line_args() -> Command<'static> { - let app = Command::new("swhkd") - .version(env!("CARGO_PKG_VERSION")) - .author(env!("CARGO_PKG_AUTHORS")) - .about("Simple Wayland HotKey Daemon") - .arg( - arg!(-c --config ) - .required(false) - .takes_value(true) - .help("Set a custom config file path."), - ) - .arg( - arg!(-C --cooldown ) - .required(false) - .takes_value(true) - .help("Set a custom repeat cooldown duration. Default is 250ms."), - ) - .arg(arg!(-d - -debug).required(false).help("Enable debug mode.")) - .arg( - arg!(-D --device ) - .required(false) - .takes_value(true) - .multiple_occurrences(true) - .help( - "Specific keyboard devices to use. Seperate multiple devices with semicolon.", - ), - ); - app -} - pub fn setup_swhkd(invoking_uid: u32, runtime_path: String) { // Set a sane process umask. log::trace!("Setting process umask."); diff --git a/swhks/Cargo.toml b/swhks/Cargo.toml index 33720f2..2cf3d28 100644 --- a/swhks/Cargo.toml +++ b/swhks/Cargo.toml @@ -7,7 +7,7 @@ version = "1.3.0-dev" authors = [ "Shinyzenith \n", "Angelo Fallaria \n", - "EdenQwQ \n" + "EdenQwQ \n", ] [dependencies] @@ -15,7 +15,7 @@ env_logger = "0.9.0" log = "0.4.14" nix = "0.23.1" sysinfo = "0.23.5" -clap = "3.1.6" +clap = { version = "4.1.0", features = ["derive"] } [[bin]] name = "swhks" diff --git a/swhks/src/main.rs b/swhks/src/main.rs index 3de2eae..f66fc32 100644 --- a/swhks/src/main.rs +++ b/swhks/src/main.rs @@ -1,4 +1,4 @@ -use clap::arg; +use clap::Parser; use environ::Env; use nix::{ sys::stat::{umask, Mode}, @@ -10,26 +10,29 @@ use std::{ env, fs, fs::OpenOptions, os::unix::net::UnixListener, - path::Path, + path::{Path, PathBuf}, process::{exit, id, Command, Stdio}, }; use sysinfo::{ProcessExt, System, SystemExt}; mod environ; +/// IPC Server for swhkd +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Args { + /// Set a custom log file. (Defaults to ${XDG_DATA_HOME:-$HOME/.local/share}/swhks-current_unix_time.log) + #[arg(short, long, value_name = "FILE")] + log: Option, + + /// Enable Debug Mode + #[arg(short, long)] + debug: bool, +} + fn main() -> std::io::Result<()> { - let app = clap::Command::new("swhks") - .version(env!("CARGO_PKG_VERSION")) - .author(env!("CARGO_PKG_AUTHORS")) - .about("IPC Server for swhkd") - .arg(arg!(-l --log ).required(false).takes_value(true).help( - "Set a custom log file. (Defaults to ${XDG_DATA_HOME:-$HOME/.local/share}/swhks-current_unix_time.log)", - )) - .arg(arg!(-d --debug).required(false).takes_value(false).help( - "Enable debug mode." - )); - let args = app.get_matches(); - if args.is_present("debug") { + let args = Args::parse(); + if args.debug { env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("swhks=trace")) .init(); } else { @@ -45,8 +48,8 @@ fn main() -> std::io::Result<()> { let (pid_file_path, sock_file_path) = get_file_paths(&environment); - let log_file_name = if let Some(val) = args.value_of("log") { - val.to_string() + let log_file_name = if let Some(val) = args.log { + val } else { let time = match SystemTime::now().duration_since(UNIX_EPOCH) { Ok(n) => n.as_secs().to_string(), @@ -56,7 +59,7 @@ fn main() -> std::io::Result<()> { } }; - format!("{}/swhks/swhks-{}.log", environment.data_home.to_string_lossy(), time) + format!("{}/swhks/swhks-{}.log", environment.data_home.to_string_lossy(), time).into() }; let log_path = Path::new(&log_file_name);