use crate::SbError;
use std::{fs, sync::Arc};
pub fn unix_timestamp() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
.try_into()
.unwrap_or(0)
}
pub fn read_and_trim_file(file_path: &str) -> Result<String, SbError> {
if !std::path::Path::new(file_path).exists() {
return Err(SbError::CustomError {
message: "File not found".to_string(),
source: Arc::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("File not found: {}", file_path),
)),
});
}
let content = fs::read_to_string(file_path).map_err(|e| SbError::CustomError {
message: "Failed to read file".to_string(),
source: Arc::new(e),
})?;
Ok(content.trim().to_string())
}