In timezones stage changing get_timezones_blocking from using systemd timedatectl to query filesystem directly.

This commit is contained in:
kira committed 2026-11-03 08:38:51 +01:00
1 parent 6f921f3ff0
commit fb90bc3092
2 files changed
+63 -3

No files matched your search

+46
View File
@@ -20,7 +20,9 @@
use crate::kira_disk_layout::*; use crate::kira_disk_layout::*;
use crate::kira_size::KiraSize; use crate::kira_size::KiraSize;
use std::fmt::format;
use std::fs; use std::fs;
use std::path::Path;
use std::process::Command; use std::process::Command;
#[derive(Debug)] #[derive(Debug)]
@@ -330,3 +332,47 @@ pub fn mkswap(dev: &str) -> Result<(), ExecCommandError> {
//mkswap -L SWAP /dev/sda4 //mkswap -L SWAP /dev/sda4
exec_command("mkswap", &vec!["-L", "bee-swap", dev]) 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<Vec<String>, std::io::Error> {
fn ls_subdir_rec(root_path: &Path, prefix: String, mut res: Vec<String>) -> Result<Vec<String>, 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<String> = 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)
}
+17 -3
View File
@@ -22,9 +22,10 @@ use crate::stage::{KiraConfig, StageAction};
use iced::{Alignment, Length, widget}; use iced::{Alignment, Length, widget};
use log; use log;
use rust_i18n::t; use rust_i18n::t;
use std::collections::HashMap; use std::{collections::HashMap, fs, path::Path};
use crate::kira_scroll_list; use crate::kira_scroll_list;
use crate::kira_system;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeZoneData { pub struct TimeZoneData {
@@ -75,7 +76,20 @@ pub enum Message {
} }
/// Getting list of awailable timezones from system. /// Getting list of awailable timezones from system.
fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, String> { fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, 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::<Vec<TimeZoneData>>())
}
/// Getting list of awailable timezones from system.
fn get_timezones_blocking_depr() -> Result<Vec<TimeZoneData>, String> {
use std::process::Command; use std::process::Command;
//timedatectl list-timezones --no-pager //timedatectl list-timezones --no-pager
match Command::new("timedatectl") match Command::new("timedatectl")
@@ -140,7 +154,7 @@ impl TimeZoneStage {
ex ex
); );
Self { Self {
time_zones: Err(ex), time_zones: Err(ex.to_string()),
regions: Vec::new(), regions: Vec::new(),
zones: Vec::new(), zones: Vec::new(),
region_id: None, region_id: None,