feat(content): add managed content metadata layout
This commit is contained in:
1 parent
a05b030862
commit
fbf8142ea0
46 files changed
+2404
-166
No files matched your search
@@ -127,6 +127,7 @@ mod tests {
|
||||
name: file_stem.to_string(),
|
||||
source_slug: None,
|
||||
installed_path: None,
|
||||
provider_project: None,
|
||||
title_suffix: None,
|
||||
footer_label: None,
|
||||
description: String::new(),
|
||||
|
||||
+2
-2
@@ -58,7 +58,7 @@ pub async fn handle_import(matches: &ArgMatches) -> CliResult {
|
||||
version.game_versions.first().unwrap_or(&"?".to_string())
|
||||
);
|
||||
|
||||
let tmp_dir = manager.meta_dir.join("tmp");
|
||||
let tmp_dir = crate::storage::MetadataPaths::new(&manager.meta_dir).temporary();
|
||||
std::fs::create_dir_all(&tmp_dir)?;
|
||||
modrinth::download_mrpack(&client, version, &tmp_dir)
|
||||
.await
|
||||
@@ -79,7 +79,7 @@ pub async fn handle_import(matches: &ArgMatches) -> CliResult {
|
||||
version.game_versions.first().unwrap_or(&"?".to_string())
|
||||
);
|
||||
|
||||
let tmp_dir = manager.meta_dir.join("tmp");
|
||||
let tmp_dir = crate::storage::MetadataPaths::new(&manager.meta_dir).temporary();
|
||||
std::fs::create_dir_all(&tmp_dir)?;
|
||||
modrinth::download_mrpack(&client, &version, &tmp_dir)
|
||||
.await
|
||||
|
||||
+2
-2
@@ -94,7 +94,7 @@ mod tests {
|
||||
#[test]
|
||||
fn resolves_latest_log_when_no_file_is_given() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = tmp.path().join("demo/.minecraft/logs/launches");
|
||||
let dir = tmp.path().join("demo/minecraft/logs/launches");
|
||||
std::fs::create_dir_all(&dir).expect("log directory should exist");
|
||||
std::fs::write(dir.join("2024-01-02_03-04-05.log"), "newer").expect("write newer log");
|
||||
std::fs::write(dir.join("2024-01-01_03-04-05.log"), "older").expect("write older log");
|
||||
@@ -109,7 +109,7 @@ mod tests {
|
||||
#[test]
|
||||
fn resolves_named_log_file() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let dir = tmp.path().join("demo/.minecraft/logs/launches");
|
||||
let dir = tmp.path().join("demo/minecraft/logs/launches");
|
||||
std::fs::create_dir_all(&dir).expect("log directory should exist");
|
||||
std::fs::write(dir.join("latest.log"), "hello").expect("write named log");
|
||||
|
||||
|
||||
@@ -24,6 +24,49 @@ pub async fn init() {
|
||||
return;
|
||||
}
|
||||
|
||||
let instances_dir = crate::config::SETTINGS.paths.resolve_instances_dir();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
if crate::layout_migration::is_needed(&instances_dir, &meta_dir) {
|
||||
let config = crate::config::get_config_path().join("config.toml");
|
||||
if let Err(error) =
|
||||
crate::layout_migration::run(&instances_dir, &meta_dir, &config, |progress| {
|
||||
eprintln!(
|
||||
"{}: {} ({}/{})",
|
||||
progress.phase, progress.item, progress.current, progress.total
|
||||
);
|
||||
})
|
||||
{
|
||||
eprintln!("error: layout migration failed safely: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
} else if let Err(error) = crate::layout_migration::initialize_new_layout(&meta_dir) {
|
||||
eprintln!("error: cannot initialize metadata layout: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
if crate::layout_migration::cache_rebuild_pending(&meta_dir) {
|
||||
let manager = crate::instance::InstanceManager::new(&instances_dir, &meta_dir);
|
||||
let instances = manager.load_all();
|
||||
for (index, instance) in instances.iter().enumerate() {
|
||||
eprintln!(
|
||||
"Rebuilding runtime cache: {} ({}/{})",
|
||||
instance.name,
|
||||
index + 1,
|
||||
instances.len()
|
||||
);
|
||||
if let Err(error) = manager.repair_runtime_cache(instance).await {
|
||||
eprintln!(
|
||||
"error: runtime cache rebuild stopped safely for '{}': {error}",
|
||||
instance.name
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
if let Err(error) = crate::layout_migration::finish_cache_rebuild(&meta_dir) {
|
||||
eprintln!("error: cannot finish runtime cache migration: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
let result = match matches.subcommand() {
|
||||
Some(("instance", sub_matches)) => instance::handle_instance(sub_matches).await,
|
||||
Some(("mod", sub_matches)) => content::handle_mod(sub_matches),
|
||||
|
||||
Reference in new issue
Block a user