mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-29 16:40:05 +08:00
update
This commit is contained in:
@@ -2,8 +2,5 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub fn is_env_on(var: &str) -> bool {
|
pub fn is_env_on(var: &str) -> bool {
|
||||||
match env::var(var) {
|
env::var(var).map(|v| v.to_lowercase()).map(|v| (v == "true" || v == "yes" || v == "1")).unwrap_or(false)
|
||||||
Err(_) => false,
|
|
||||||
Ok(v) => (v == "TRUE" || v == "true" || v =="YES" || v == "yes" || v == "1"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
iff,
|
||||||
util_os,
|
util_os,
|
||||||
util_io,
|
util_io,
|
||||||
new_box_ioerror,
|
new_box_ioerror,
|
||||||
@@ -13,11 +14,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_home_str() -> Option<String> {
|
pub fn get_home_str() -> Option<String> {
|
||||||
if util_os::is_macos_or_linux() {
|
iff!(util_os::is_macos_or_linux(), env::var("HOME").ok(), None)
|
||||||
env::var("HOME").ok()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_home_path() -> Option<PathBuf> {
|
pub fn get_home_path() -> Option<PathBuf> {
|
||||||
@@ -25,12 +22,11 @@ pub fn get_home_path() -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_absolute_path(path: &str) -> Option<PathBuf> {
|
pub fn get_absolute_path(path: &str) -> Option<PathBuf> {
|
||||||
if path == "~" {
|
match path {
|
||||||
return Some(PathBuf::from(get_home_str()?));
|
"~" => Some(PathBuf::from(get_home_str()?)),
|
||||||
} else if path.starts_with("~/") {
|
path if path.starts_with("~/") => Some(PathBuf::from(&format!("{}/{}", get_home_str()?, &path[2..]))),
|
||||||
return Some(PathBuf::from(&format!("{}/{}", get_home_str()?, &path[2..])));
|
path => fs::canonicalize(path).ok(),
|
||||||
}
|
}
|
||||||
fs::canonicalize(path).ok()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_file_content(file: &str) -> XResult<String> {
|
pub fn read_file_content(file: &str) -> XResult<String> {
|
||||||
@@ -41,10 +37,7 @@ pub fn read_file_content(file: &str) -> XResult<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_symlink(path: &Path) -> bool {
|
pub fn is_symlink(path: &Path) -> bool {
|
||||||
match path.symlink_metadata() {
|
path.symlink_metadata().map(|meta| meta.file_type().is_symlink()).unwrap_or(false)
|
||||||
Err(_) => false,
|
|
||||||
Ok(meta) => meta.file_type().is_symlink(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_dir<FError, FProcess, FFilter>(dir: &Path,
|
pub fn walk_dir<FError, FProcess, FFilter>(dir: &Path,
|
||||||
|
|||||||
Reference in New Issue
Block a user