From fb90bc3092e3d8150c719decdd86868b9b0dec61198b41b32fdb1c2e7769833e Mon Sep 17 00:00:00 2001 From: kira Date: Tue, 3 Nov 2026 08:38:51 +0100 Subject: [PATCH] In timezones stage changing get_timezones_blocking from using systemd timedatectl to query filesystem directly. --- src/kira_system.rs | 46 ++++++++++++++++++++++++++++++++++++++ src/stages/timezone/mod.rs | 20 ++++++++++++++--- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/kira_system.rs b/src/kira_system.rs index 12f951e..b95ee2b 100644 --- a/src/kira_system.rs +++ b/src/kira_system.rs @@ -20,7 +20,9 @@ use crate::kira_disk_layout::*; use crate::kira_size::KiraSize; +use std::fmt::format; use std::fs; +use std::path::Path; use std::process::Command; #[derive(Debug)] @@ -330,3 +332,47 @@ pub fn mkswap(dev: &str) -> Result<(), ExecCommandError> { //mkswap -L SWAP /dev/sda4 exec_command("mkswap", &vec!["-L", "bee-swap", dev]) } + +/// +/// Returns list of files in directory and all subdirectories +/// Files in subdirectories listed with path related to specified dir +/// for example subdir1/subdir2/file +/// +pub fn ls_dir_rec(dir_part: &Path) -> Result, std::io::Error> { + + fn ls_subdir_rec(root_path: &Path, prefix: String, mut res: Vec) -> Result, std::io::Error> { + if root_path.is_dir() { + for dir_entry in fs::read_dir(root_path)? { + let dir_entry = dir_entry?; + let dir_entry_path = dir_entry.path(); + let next_prefix = format!("{}/{}", prefix, dir_entry.file_name().to_string_lossy()); + if dir_entry_path.is_dir() { + + res = ls_subdir_rec(&dir_entry_path, next_prefix, res)?; + } + else { + res.push(next_prefix); + } + } + } + Ok(res) + } + + let mut res: Vec = Vec::new(); + //let loc_path: &Path = Path::new("/usr/share/zoneinfo"); + + if dir_part.is_dir() { + for d_entry in fs::read_dir(dir_part)? { + let d_entry = d_entry?; + let d_entry_path = d_entry.path(); + let d_entry_name = d_entry.file_name().to_string_lossy().to_string(); + if d_entry_path.is_dir() { + res = ls_subdir_rec(&d_entry_path, d_entry_name, res)?; + } else { + // Add file to list + res.push(d_entry_name); + } + } + } + Ok(res) +} \ No newline at end of file diff --git a/src/stages/timezone/mod.rs b/src/stages/timezone/mod.rs index 8d9a7b1..038e290 100644 --- a/src/stages/timezone/mod.rs +++ b/src/stages/timezone/mod.rs @@ -22,9 +22,10 @@ use crate::stage::{KiraConfig, StageAction}; use iced::{Alignment, Length, widget}; use log; use rust_i18n::t; -use std::collections::HashMap; +use std::{collections::HashMap, fs, path::Path}; use crate::kira_scroll_list; +use crate::kira_system; #[derive(Debug, Clone, PartialEq, Eq)] pub struct TimeZoneData { @@ -75,7 +76,20 @@ pub enum Message { } /// Getting list of awailable timezones from system. -fn get_timezones_blocking() -> Result, String> { +fn get_timezones_blocking() -> Result, kira_system::ExecCommandError> { + let loc_path: &Path = Path::new("/usr/share/zoneinfo"); + + let tz_list = kira_system::ls_dir_rec(loc_path)?; + + Ok(tz_list + .iter() + .filter(|sb| sb.contains('/')) + .filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim())) + .collect::>()) +} + +/// Getting list of awailable timezones from system. +fn get_timezones_blocking_depr() -> Result, String> { use std::process::Command; //timedatectl list-timezones --no-pager match Command::new("timedatectl") @@ -140,7 +154,7 @@ impl TimeZoneStage { ex ); Self { - time_zones: Err(ex), + time_zones: Err(ex.to_string()), regions: Vec::new(), zones: Vec::new(), region_id: None,