replace custom home_dir

This commit is contained in:
jb-alvarado 2024-05-27 12:14:50 +02:00
parent 172006627f
commit c526f09c0c
6 changed files with 5 additions and 65 deletions

1
Cargo.lock generated
View File

@ -1365,6 +1365,7 @@ dependencies = [
"derive_more", "derive_more",
"ffprobe", "ffprobe",
"file-rotate", "file-rotate",
"home",
"lazy_static", "lazy_static",
"lettre", "lettre",
"lexical-sort", "lexical-sort",

View File

@ -112,7 +112,7 @@ pub fn norm_abs_path(
let path = &root_path.join(&source_relative); let path = &root_path.join(&source_relative);
if !FOLDER_WHITELIST.iter().any(|f| path.starts_with(f)) if !FOLDER_WHITELIST.iter().any(|f| path.starts_with(f))
&& !path.starts_with(&HOME_DIR.to_string()) && !path.starts_with(HOME_DIR.to_string())
{ {
return Err(ServiceError::Forbidden( return Err(ServiceError::Forbidden(
"Access forbidden: Folder cannot be opened.".to_string(), "Access forbidden: Folder cannot be opened.".to_string(),

View File

@ -14,6 +14,7 @@ crossbeam-channel = "0.5"
derive_more = "0.99" derive_more = "0.99"
ffprobe = "0.4" ffprobe = "0.4"
file-rotate = "0.7" file-rotate = "0.7"
home = "0.5"
lazy_static = "1.4" lazy_static = "1.4"
lettre = { version = "0.11", features = ["builder", "rustls-tls", "smtp-transport"], default-features = false } lettre = { version = "0.11", features = ["builder", "rustls-tls", "smtp-transport"], default-features = false }
lexical-sort = "0.3" lexical-sort = "0.3"

View File

@ -15,7 +15,7 @@ use shlex::split;
use crate::AdvancedConfig; use crate::AdvancedConfig;
use super::vec_strings; use super::vec_strings;
use crate::utils::{free_tcp_socket, home_dir, time_to_sec, OutputMode::*}; use crate::utils::{free_tcp_socket, time_to_sec, OutputMode::*};
pub const DUMMY_LEN: f64 = 60.0; pub const DUMMY_LEN: f64 = 60.0;
pub const IMAGE_FORMAT: [&str; 21] = [ pub const IMAGE_FORMAT: [&str; 21] = [
@ -406,7 +406,7 @@ impl PlayoutConfig {
config.general.config_path = config_path.to_string_lossy().to_string(); config.general.config_path = config_path.to_string_lossy().to_string();
config.general.stat_file = home_dir() config.general.stat_file = home::home_dir()
.unwrap_or_else(env::temp_dir) .unwrap_or_else(env::temp_dir)
.join(if config.general.stat_file.is_empty() { .join(if config.general.stat_file.is_empty() {
".ffp_status" ".ffp_status"

View File

@ -10,9 +10,6 @@ use std::{
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
#[cfg(not(windows))]
use std::env;
use chrono::{prelude::*, TimeDelta}; use chrono::{prelude::*, TimeDelta};
use ffprobe::{ffprobe, Stream as FFStream}; use ffprobe::{ffprobe, Stream as FFStream};
use rand::prelude::*; use rand::prelude::*;
@ -33,9 +30,6 @@ pub mod json_serializer;
mod json_validate; mod json_validate;
mod logging; mod logging;
#[cfg(windows)]
mod windows;
pub use config::{ pub use config::{
self as playout_config, self as playout_config,
OutputMode::{self, *}, OutputMode::{self, *},
@ -988,19 +982,6 @@ pub fn custom_format<T: fmt::Display>(template: &str, args: &[T]) -> String {
filled_template filled_template
} }
pub fn home_dir() -> Option<PathBuf> {
home_dir_inner()
}
#[cfg(windows)]
use windows::home_dir_inner;
#[cfg(any(unix, target_os = "redox"))]
fn home_dir_inner() -> Option<PathBuf> {
#[allow(deprecated)]
env::home_dir()
}
/// Get system time, in non test/debug case. /// Get system time, in non test/debug case.
#[cfg(not(any(test, debug_assertions)))] #[cfg(not(any(test, debug_assertions)))]
pub fn time_now() -> DateTime<Local> { pub fn time_now() -> DateTime<Local> {

View File

@ -1,43 +0,0 @@
use std::{env, ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf, ptr};
use winapi::shared::minwindef::MAX_PATH;
use winapi::shared::winerror::S_OK;
use winapi::um::shlobj::{SHGetFolderPathW, CSIDL_PROFILE};
pub fn home_dir_inner() -> Option<PathBuf> {
env::var_os("USERPROFILE")
.filter(|s| !s.is_empty())
.map(PathBuf::from)
.or_else(home_dir_crt)
}
#[cfg(not(target_vendor = "uwp"))]
fn home_dir_crt() -> Option<PathBuf> {
unsafe {
let mut path: Vec<u16> = Vec::with_capacity(MAX_PATH);
match SHGetFolderPathW(
ptr::null_mut(),
CSIDL_PROFILE,
ptr::null_mut(),
0,
path.as_mut_ptr(),
) {
S_OK => {
let len = wcslen(path.as_ptr());
path.set_len(len);
let s = OsString::from_wide(&path);
Some(PathBuf::from(s))
}
_ => None,
}
}
}
#[cfg(target_vendor = "uwp")]
fn home_dir_crt() -> Option<PathBuf> {
None
}
extern "C" {
fn wcslen(buf: *const u16) -> usize;
}