0.8.0 beta fixes (#2154)

* initial fixes

* 0.8.0 beta fixes

* run actions

* run fmt

* Fix windows build

* Add purge cache opt

* add must revalidate to project req

* lint + clippy

* fix processes, open folder

* Update migrator to use old launcher cache for perf

* fix empty dirs not moving

* fix lint + create natives dir if not exist

* fix large request batches

* finish

* Fix deep linking on mac

* fix comp err

* fix comp err (2)

---------

Signed-off-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Geometrically
2024-08-16 23:20:11 -07:00
committed by GitHub
parent 3a4843fb46
commit 910e219c0e
66 changed files with 1961 additions and 1896 deletions

View File

@@ -1,6 +1,6 @@
use crate::state::{
CachedEntry, Organization, Project, SearchResults, TeamMember, User,
Version,
CacheBehaviour, CacheValueType, CachedEntry, Organization, Project,
SearchResults, TeamMember, User, Version,
};
macro_rules! impl_cache_methods {
@@ -10,15 +10,17 @@ macro_rules! impl_cache_methods {
#[tracing::instrument]
pub async fn [<get_ $variant:snake>](
id: &str,
cache_behaviour: Option<CacheBehaviour>,
) -> crate::Result<Option<$type>>
{
let state = crate::State::get().await?;
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], None, &state.pool, &state.api_semaphore).await?.into_iter().next())
Ok(CachedEntry::[<get_ $variant:snake _many>](&[id], cache_behaviour, &state.pool, &state.api_semaphore).await?.into_iter().next())
}
#[tracing::instrument]
pub async fn [<get_ $variant:snake _many>](
ids: &[&str],
cache_behaviour: Option<CacheBehaviour>,
) -> crate::Result<Vec<$type>>
{
let state = crate::State::get().await?;
@@ -40,3 +42,12 @@ impl_cache_methods!(
(Organization, Organization),
(SearchResults, SearchResults)
);
pub async fn purge_cache_types(
cache_types: &[CacheValueType],
) -> crate::Result<()> {
let state = crate::State::get().await?;
CachedEntry::purge_cache_types(cache_types, &state.pool).await?;
Ok(())
}

View File

@@ -19,7 +19,7 @@ pub async fn get_minecraft_versions() -> crate::Result<VersionManifest> {
Ok(minecraft_versions)
}
#[tracing::instrument]
// #[tracing::instrument]
pub async fn get_loader_versions(loader: &str) -> crate::Result<Manifest> {
let state = State::get().await?;
let loaders = CachedEntry::get_loader_manifest(

View File

@@ -14,11 +14,11 @@ pub mod tags;
pub mod data {
pub use crate::state::{
Credentials, Dependency, DirectoryInfo, Hooks, JavaVersion, LinkedData,
MemorySettings, ModLoader, ModrinthCredentials,
ModrinthCredentialsResult, Organization, Process, ProfileFile, Project,
ProjectType, SearchResult, SearchResults, Settings, TeamMember, Theme,
User, Version, WindowSize,
CacheBehaviour, CacheValueType, Credentials, Dependency, DirectoryInfo,
Hooks, JavaVersion, LinkedData, MemorySettings, ModLoader,
ModrinthCredentials, ModrinthCredentialsResult, Organization,
ProcessMetadata, ProfileFile, Project, ProjectType, SearchResult,
SearchResults, Settings, TeamMember, Theme, User, Version, WindowSize,
};
}

View File

@@ -174,8 +174,7 @@ async fn load_instance_cfg(file_path: &Path) -> crate::Result<MMCInstance> {
}
}
#[tracing::instrument]
// #[tracing::instrument]
pub async fn import_mmc(
mmc_base_path: PathBuf, // path to base mmc folder
instance_folder: String, // instance folder in mmc_base_path

View File

@@ -104,7 +104,7 @@ pub async fn get_importable_instances(
// Import an instance from a launcher type and base path
// Note: this *deletes* the submitted empty profile
#[tracing::instrument]
// #[tracing::instrument]
pub async fn import_instance(
profile_path: &str, // This should be a blank profile
launcher_type: ImportLauncherType,
@@ -257,7 +257,7 @@ pub async fn copy_dotminecraft(
crate::api::profile::get_full_path(profile_path_id).await?;
// Gets all subfiles recursively in src
let subfiles = get_all_subfiles(&dotminecraft).await?;
let subfiles = get_all_subfiles(&dotminecraft, true).await?;
let total_subfiles = subfiles.len() as u64;
let loading_bar = init_or_edit_loading(
@@ -297,20 +297,33 @@ pub async fn copy_dotminecraft(
#[async_recursion::async_recursion]
#[tracing::instrument]
pub async fn get_all_subfiles(src: &Path) -> crate::Result<Vec<PathBuf>> {
pub async fn get_all_subfiles(
src: &Path,
include_empty_dirs: bool,
) -> crate::Result<Vec<PathBuf>> {
if !src.is_dir() {
return Ok(vec![src.to_path_buf()]);
}
let mut files = Vec::new();
let mut dir = io::read_dir(&src).await?;
let mut has_files = false;
while let Some(child) = dir
.next_entry()
.await
.map_err(|e| IOError::with_path(e, src))?
{
has_files = true;
let src_child = child.path();
files.append(&mut get_all_subfiles(&src_child).await?);
files.append(
&mut get_all_subfiles(&src_child, include_empty_dirs).await?,
);
}
if !has_files && include_empty_dirs {
files.push(src.to_path_buf());
}
Ok(files)
}

View File

@@ -177,31 +177,25 @@ pub async fn install_zipped_mrpack_files(
let path =
std::path::Path::new(&project_path).components().next();
if let Some(path) = path {
match path {
Component::CurDir | Component::Normal(_) => {
let path =
profile::get_full_path(&profile_path)
.await?
.join(&project_path);
if let Some(Component::CurDir | Component::Normal(_)) = path
{
let path = profile::get_full_path(&profile_path)
.await?
.join(&project_path);
cache_file_hash(
file.clone(),
&profile_path,
&project_path,
project
.hashes
.get(&PackFileHash::Sha1)
.map(|x| &**x),
&state.pool,
)
.await?;
cache_file_hash(
file.clone(),
&profile_path,
&project_path,
project
.hashes
.get(&PackFileHash::Sha1)
.map(|x| &**x),
&state.pool,
)
.await?;
write(&path, &file, &state.io_semaphore)
.await?;
}
_ => {}
};
write(&path, &file, &state.io_semaphore).await?;
}
Ok(())
}

View File

@@ -1,16 +1,17 @@
//! Theseus process management interface
use crate::state::Process;
use crate::state::ProcessMetadata;
pub use crate::{
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
State,
};
use uuid::Uuid;
// Gets the Profile paths of each *running* stored process in the state
#[tracing::instrument]
pub async fn get_all() -> crate::Result<Vec<Process>> {
pub async fn get_all() -> crate::Result<Vec<ProcessMetadata>> {
let state = State::get().await?;
let processes = Process::get_all(&state.pool).await?;
let processes = state.process_manager.get_all();
Ok(processes)
}
@@ -18,39 +19,31 @@ pub async fn get_all() -> crate::Result<Vec<Process>> {
#[tracing::instrument]
pub async fn get_by_profile_path(
profile_path: &str,
) -> crate::Result<Vec<Process>> {
) -> crate::Result<Vec<ProcessMetadata>> {
let state = State::get().await?;
let processes =
Process::get_from_profile(profile_path, &state.pool).await?;
let processes = state
.process_manager
.get_all()
.into_iter()
.filter(|x| x.profile_path == profile_path)
.collect();
Ok(processes)
}
// Kill a child process stored in the state by UUID, as a string
#[tracing::instrument]
pub async fn kill(pid: i32) -> crate::Result<()> {
pub async fn kill(uuid: Uuid) -> crate::Result<()> {
let state = State::get().await?;
let process = Process::get(pid, &state.pool).await?;
state.process_manager.kill(uuid).await?;
if let Some(process) = process {
process.kill().await?;
Ok(())
} else {
Ok(())
}
Ok(())
}
// Wait for a child process stored in the state by UUID
#[tracing::instrument]
pub async fn wait_for(pid: i32) -> crate::Result<()> {
pub async fn wait_for(uuid: Uuid) -> crate::Result<()> {
let state = State::get().await?;
let process = Process::get(pid, &state.pool).await?;
state.process_manager.wait_for(uuid).await?;
if let Some(process) = process {
process.wait_for().await?;
Ok(())
} else {
Ok(())
}
Ok(())
}

View File

@@ -8,7 +8,7 @@ use crate::pack::install_from::{
EnvType, PackDependency, PackFile, PackFileHash, PackFormat,
};
use crate::state::{
CacheBehaviour, CachedEntry, Credentials, JavaVersion, Process,
CacheBehaviour, CachedEntry, Credentials, JavaVersion, ProcessMetadata,
ProfileFile, ProjectType, SideType,
};
@@ -71,12 +71,13 @@ pub async fn get_many(paths: &[&str]) -> crate::Result<Vec<Profile>> {
#[tracing::instrument]
pub async fn get_projects(
path: &str,
cache_behaviour: Option<CacheBehaviour>,
) -> crate::Result<DashMap<String, ProfileFile>> {
let state = State::get().await?;
if let Some(profile) = get(path).await? {
let files = profile
.get_projects(None, &state.pool, &state.api_semaphore)
.get_projects(cache_behaviour, &state.pool, &state.api_semaphore)
.await?;
Ok(files)
@@ -614,10 +615,10 @@ fn pack_get_relative_path(
/// Run Minecraft using a profile and the default credentials, logged in credentials,
/// failing with an error if no credentials are available
#[tracing::instrument]
pub async fn run(path: &str) -> crate::Result<Process> {
pub async fn run(path: &str) -> crate::Result<ProcessMetadata> {
let state = State::get().await?;
let default_account = Credentials::get_active(&state.pool)
let default_account = Credentials::get_default_credential(&state.pool)
.await?
.ok_or_else(|| crate::ErrorKind::NoCredentialsError.as_error())?;
@@ -631,7 +632,7 @@ pub async fn run(path: &str) -> crate::Result<Process> {
pub async fn run_credentials(
path: &str,
credentials: &Credentials,
) -> crate::Result<Process> {
) -> crate::Result<ProcessMetadata> {
let state = State::get().await?;
let settings = Settings::get(&state.pool).await?;
let profile = get(path).await?.ok_or_else(|| {
@@ -652,7 +653,7 @@ pub async fn run_credentials(
if let Some(command) = cmd.next() {
let full_path = get_full_path(&profile.path).await?;
let result = Command::new(command)
.args(&cmd.collect::<Vec<&str>>())
.args(cmd.collect::<Vec<&str>>())
.current_dir(&full_path)
.spawn()
.map_err(|e| IOError::with_path(e, &full_path))?
@@ -715,10 +716,11 @@ pub async fn run_credentials(
}
pub async fn kill(path: &str) -> crate::Result<()> {
let state = State::get().await?;
let processes = crate::api::process::get_by_profile_path(path).await?;
for process in processes {
process.kill().await?;
state.process_manager.kill(process.uuid).await?;
}
Ok(())
@@ -920,5 +922,8 @@ pub async fn add_all_recursive_folder_paths(
}
pub fn sanitize_profile_name(input: &str) -> String {
input.replace(['/', '\\', '?', '*', ':', '\'', '\"', '|', '<', '>'], "_")
input.replace(
['/', '\\', '?', '*', ':', '\'', '\"', '|', '<', '>', '!'],
"_",
)
}

View File

@@ -21,3 +21,18 @@ pub async fn set(settings: Settings) -> crate::Result<()> {
Ok(())
}
#[tracing::instrument]
pub async fn cancel_directory_change() -> crate::Result<()> {
let pool = crate::state::db::connect().await?;
let mut settings = Settings::get(&pool).await?;
if let Some(prev_custom_dir) = settings.prev_custom_dir {
settings.prev_custom_dir = None;
settings.custom_dir = Some(prev_custom_dir);
}
settings.update(&pool).await?;
Ok(())
}