Page MenuHomePhorge

globals.rs
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

globals.rs

use global_placeholders::init;
use macros_rs::crashln;
use once_cell::sync::OnceCell;
use pmc::{config, file::Exists, helpers};
use serde::{Deserialize, Serialize};
use std::fs;
use utoipa::ToSchema;
#[derive(Clone, Serialize, Deserialize, ToSchema)]
pub struct Os {
pub name: os_info::Type,
pub version: String,
pub arch: String,
pub bitness: os_info::Bitness,
}
pub static OS_INFO: OnceCell<Os> = OnceCell::new();
pub fn get_os_info() -> &'static Os {
OS_INFO.get_or_init(|| {
let os = os_info::get();
Os {
name: os.os_type(),
version: os.version().to_string(),
arch: os.architecture().unwrap().into(),
bitness: os.bitness(),
}
})
}
pub(crate) fn init() {
match home::home_dir() {
Some(path) => {
let path = path.display();
if !Exists::check(&format!("{path}/.pmc/")).folder() {
fs::create_dir_all(format!("{path}/.pmc/")).unwrap();
log::info!("created pmc base dir");
}
let config = config::read();
if !Exists::check(&config.runner.log_path).folder() {
fs::create_dir_all(&config.runner.log_path).unwrap();
log::info!("created pmc log dir");
}
init!("pmc.base", format!("{path}/.pmc/"));
init!("pmc.log", format!("{path}/.pmc/pmc.log"));
init!("pmc.pid", format!("{path}/.pmc/daemon.pid"));
init!("pmc.dump", format!("{path}/.pmc/process.dump"));
init!("pmc.daemon.kind", config.daemon.kind);
init!("pmc.daemon.log", format!("{path}/.pmc/daemon.log"));
let out = format!("{}/{{}}-out.log", config.runner.log_path);
let error = format!("{}/{{}}-error.log", config.runner.log_path);
init!("pmc.logs.out", out);
init!("pmc.logs.error", error);
}
None => crashln!("{} Impossible to get your home directory", *helpers::FAIL),
}
}
pub(crate) fn defaults(name: &Option<String>) -> String {
match name {
Some(name) => name.clone(),
None => config::read().default,
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 16, 4:09 AM (1 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
484910
Default Alt Text
globals.rs (2 KB)

Event Timeline