Skip to content

Commit

Permalink
Merge branch 'develop' into steam-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Nov 20, 2024
2 parents d1ba78a + d34a638 commit 8c0fdf8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- GPU acceleration for SteamVR overlays (Community contribution by [BenjaminZehowlt](https://github.com/BenjaminZehowlt))

### Fixed

- Possible crash when encountering time issues on log cleanup

## [1.14.6]

### Fixed
Expand Down
91 changes: 86 additions & 5 deletions src-core/src/commands/log_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::info;
use std::path::PathBuf;
use log::{error, info};
use std::{path::PathBuf, time::SystemTime};
use tokio::sync::Mutex;

lazy_static! {
Expand Down Expand Up @@ -31,6 +31,74 @@ pub async fn clear_log_files() {
info!("[Core] Deleted {} log file(s)", logs_deleted);
}

pub async fn print_file_debug_data(path: PathBuf) {
error!("<FILE DEBUG DATA>");
error!("Path: {:?}", path);
let now = SystemTime::now();
error!("System Time: {:?}", now);
// Print now as unix time
match now.duration_since(SystemTime::UNIX_EPOCH) {
Ok(duration) => {
error!("System Time [UNIX]: {}", duration.as_secs())
}
Err(e) => {
error!("Error getting unix time for now: {}", e);
}
};
match std::fs::metadata(&path) {
Ok(metadata) => {
// Print modified time
match metadata.modified() {
Ok(modified) => {
error!("Modified Time: {:?}", modified);
match modified.elapsed() {
Ok(elapsed) => {
error!("Elapsed Time: {:?}", elapsed);
}
Err(e) => {
error!("Error getting elapsed time for log file: {}", e);
}
};
}
Err(e) => {
error!("Error getting modified time for log file: {}", e);
}
};
// Print elapsed time
match metadata.modified() {
Ok(modified) => match modified.elapsed() {
Ok(elapsed) => {
error!("Elapsed Time [UNIX]: {}", elapsed.as_secs());
}
Err(e) => {
error!("Error getting elapsed time for log file: {}", e);
}
},
Err(e) => {
error!("Error getting modified time for log file: {}", e);
}
};
// Print modified as unix time
match metadata
.modified()
.unwrap()
.duration_since(SystemTime::UNIX_EPOCH)
{
Ok(duration) => {
error!("Modified Time [UNIX]: {}", duration.as_secs())
}
Err(e) => {
error!("Error getting unix time for modified: {}", e);
}
};
}
Err(e) => {
error!("Error getting metadata for log file: {}", e);
}
};
error!("</FILE DEBUG DATA>");
}

pub async fn clean_log_files() {
info!("[Core] Cleaning old and oversized log files...");
let guard = LOG_DIR.lock().await;
Expand All @@ -42,10 +110,23 @@ pub async fn clean_log_files() {
if path.is_file() {
let metadata = std::fs::metadata(&path).unwrap();
let too_large = metadata.len() > 10 * 1024 * 1024; // 10 MB
let too_old =
metadata.modified().unwrap().elapsed().unwrap().as_secs() > 60 * 60 * 24 * 30; // 30 Days
let too_old = match metadata.modified() {
Ok(modified) => match modified.elapsed() {
Ok(elapsed) => elapsed.as_secs() > 60 * 60 * 24 * 30, // 30 Days
Err(e) => {
error!("Error getting elapsed time for log file: {}", e);
print_file_debug_data(path.clone()).await;
false
}
},
Err(e) => {
error!("Error getting modified time for log file: {}", e);
print_file_debug_data(path.clone()).await;
false
}
};
if too_large || too_old {
if std::fs::remove_file(path).is_ok() {
if std::fs::remove_file(path.clone()).is_ok() {
logs_deleted += 1;
}
}
Expand Down

0 comments on commit 8c0fdf8

Please sign in to comment.