* not compiling; just to commit

* working logs commit

* prettier; clippy

* delete logs functions

* Reverted change

* mislabeled doc tag
This commit is contained in:
Wyatt Verchere
2023-05-03 09:02:34 -07:00
committed by GitHub
parent 713a915161
commit edd9f28081
11 changed files with 275 additions and 9 deletions

View File

@@ -2,7 +2,8 @@ use super::Profile;
use std::path::{Path, PathBuf};
use std::process::ExitStatus;
use std::{collections::HashMap, sync::Arc};
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::fs::File;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::Child;
use tokio::process::Command;
use tokio::process::{ChildStderr, ChildStdout};
@@ -40,6 +41,8 @@ impl Children {
&mut self,
uuid: Uuid,
profile_path: PathBuf,
stdout_log_path: PathBuf,
stderr_log_path: PathBuf,
mut mc_command: Command,
post_command: Option<Command>, // Command to run after minecraft.
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
@@ -47,7 +50,7 @@ impl Children {
let mut child = mc_command.spawn()?;
// Create std watcher threads for stdout and stderr
let stdout = SharedOutput::new();
let stdout = SharedOutput::build(&stdout_log_path).await?;
if let Some(child_stdout) = child.stdout.take() {
let stdout_clone = stdout.clone();
tokio::spawn(async move {
@@ -56,7 +59,7 @@ impl Children {
}
});
}
let stderr = SharedOutput::new();
let stderr = SharedOutput::build(&stderr_log_path).await?;
if let Some(child_stderr) = child.stderr.take() {
let stderr_clone = stderr.clone();
tokio::spawn(async move {
@@ -270,16 +273,18 @@ impl Default for Children {
// SharedOutput, a wrapper around a String that can be read from and written to concurrently
// Designed to be used with ChildStdout and ChildStderr in a tokio thread to have a simple String storage for the output of a child process
#[derive(Clone, Debug)]
#[derive(Debug, Clone)]
pub struct SharedOutput {
output: Arc<RwLock<String>>,
log_file: Arc<RwLock<File>>,
}
impl SharedOutput {
fn new() -> Self {
SharedOutput {
async fn build(log_file_path: &Path) -> crate::Result<Self> {
Ok(SharedOutput {
output: Arc::new(RwLock::new(String::new())),
}
log_file: Arc::new(RwLock::new(File::create(log_file_path).await?)),
})
}
// Main entry function to a created SharedOutput, returns the log as a String
@@ -300,6 +305,10 @@ impl SharedOutput {
let mut output = self.output.write().await;
output.push_str(&line);
}
{
let mut log_file = self.log_file.write().await;
log_file.write_all(line.as_bytes()).await?;
}
line.clear();
}
Ok(())

View File

@@ -116,6 +116,14 @@ impl DirectoryInfo {
self.config_dir.join("profiles")
}
/// Gets the logs dir for a given profile
#[inline]
pub fn profile_logs_dir(&self, profile: uuid::Uuid) -> PathBuf {
self.profiles_dir()
.join(profile.to_string())
.join("modrinth_logs")
}
/// Get the file containing the global database
#[inline]
pub fn database_file(&self) -> PathBuf {

View File

@@ -358,7 +358,9 @@ pub async fn infer_data_from_files(
.filter(|x| x.team_id == project.team)
.cloned()
.collect::<Vec<_>>(),
update_version: update_versions.get(&hash).map(|val| Box::new(val.clone())),
update_version: update_versions
.get(&hash)
.map(|val| Box::new(val.clone())),
incompatible: !version.loaders.contains(
&profile