diff options
Diffstat (limited to 'init/src/host')
| -rw-r--r-- | init/src/host/locale.rs | 21 | ||||
| -rw-r--r-- | init/src/host/set.rs | 2 | ||||
| -rw-r--r-- | init/src/host/timezone.rs | 2 |
3 files changed, 20 insertions, 5 deletions
diff --git a/init/src/host/locale.rs b/init/src/host/locale.rs index 6dc43b2..d955297 100644 --- a/init/src/host/locale.rs +++ b/init/src/host/locale.rs @@ -1,9 +1,22 @@ +// NOTE: Ts file contains setting localisation by environment variables +// Main logic implemented but how i think it can contain with broken logic or checks +// At least if check failed it set C.UTF8 (fallback locale) +// And why is std::env::set_var unsafe???? + use crate::host::timezone::set_timezone; use crate::log::{log_success, log_warning}; use std::fs; use std::io::Write; use std::process::Command; +/// Main function which setting system locale. +/// +/// Logic && Checks +/// 1. Reading /etc/default/locale to find needed language. +/// If it broken/has syntax errors skipping this step +/// 2. Checking for locale avalible (also switching `-` and `_`), +/// if not uses fallback locale. +/// pub fn set_locale(locale: Option<String>) -> Result<(), Box<dyn std::error::Error>> { let loc = match locale { Some(l) => l, @@ -23,10 +36,10 @@ pub fn set_locale(locale: Option<String>) -> Result<(), Box<dyn std::error::Erro } } - if let Ok(lang_env) = std::env::var("LANG") - && !lang_env.is_empty() { - return set_system_locale(&lang_env); - + if let Ok(lang_env) = std::env::var("LANG") + && !lang_env.is_empty() + { + return set_system_locale(&lang_env); } if locale_exists("C.UTF-8") { "C.UTF-8".to_string() diff --git a/init/src/host/set.rs b/init/src/host/set.rs index 9550b29..b161930 100644 --- a/init/src/host/set.rs +++ b/init/src/host/set.rs @@ -1,3 +1,5 @@ +// This file named `set.rs` because possibly here will be other functions, not only hn + use crate::log::log_warning; use libc::{c_char, sethostname, size_t}; use std::{ffi::CString, fs, io}; diff --git a/init/src/host/timezone.rs b/init/src/host/timezone.rs index 2da9e85..1062a8b 100644 --- a/init/src/host/timezone.rs +++ b/init/src/host/timezone.rs @@ -1,6 +1,6 @@ use crate::log::*; use std::fs; - + pub fn set_timezone(timezone: Option<String>) -> Result<(), Box<dyn std::error::Error>> { let tz = match timezone { Some(tz) => tz, |
