- re-export 可见性:synced_options_path 改从 files 导入;SyncedOptionJoinResolution 改从 pending 导入 - bind 移动语义:18 处 .bind(x) 改为 .bind(&x)(metadata.instance.id / option_id / custom_id 等) - storage.rs:SqliteRow 字段访问改为 row.get() - modpack.rs:去掉 Axolotl 独有的 DownloadMeta/DownloadReason,改用本地 5 参数 fetch - state/mod.rs:补齐第 2 处 State 初始化的新增字段
This commit is contained in:
1 parent
fae16a0184
commit
b7c16594ce
10 files changed
+42
-40
No files matched your search
@@ -2,10 +2,9 @@ use super::COMMAND_HISTORY_FILE;
|
|||||||
use super::files::{
|
use super::files::{
|
||||||
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
||||||
finish_checkpoint, instance_game_dir, sha1_bytes, sha1_file,
|
finish_checkpoint, instance_game_dir, sha1_bytes, sha1_file,
|
||||||
|
synced_options_path,
|
||||||
};
|
};
|
||||||
use super::orchestration::{
|
use super::orchestration::{create_synced_directories, option_effective};
|
||||||
create_synced_directories, option_effective, synced_options_path,
|
|
||||||
};
|
|
||||||
use crate::State;
|
use crate::State;
|
||||||
use crate::state::{InstanceMetadata, SyncedOption};
|
use crate::state::{InstanceMetadata, SyncedOption};
|
||||||
use crate::util::io;
|
use crate::util::io;
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ pub(in crate::api::instance) async fn detach_instance(
|
|||||||
"DELETE FROM instance_sync_checkpoints
|
"DELETE FROM instance_sync_checkpoints
|
||||||
WHERE instance_id = ? AND feature = ?",
|
WHERE instance_id = ? AND feature = ?",
|
||||||
)
|
)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(feature)
|
.bind(feature)
|
||||||
.execute(&state.pool)
|
.execute(&state.pool)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -150,7 +150,7 @@ pub(in crate::api::instance) async fn prepare_instance_update_with_state(
|
|||||||
sqlx::query(
|
sqlx::query(
|
||||||
"DELETE FROM instance_game_option_update_state WHERE instance_id = ?",
|
"DELETE FROM instance_game_option_update_state WHERE instance_id = ?",
|
||||||
)
|
)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.execute(&state.pool)
|
.execute(&state.pool)
|
||||||
.await?;
|
.await?;
|
||||||
if sync_is_active_for_instance(metadata, state).await? {
|
if sync_is_active_for_instance(metadata, state).await? {
|
||||||
@@ -184,7 +184,7 @@ pub(in crate::api::instance) async fn prepare_instance_update_with_state(
|
|||||||
had_file = excluded.had_file, sha1 = excluded.sha1,
|
had_file = excluded.had_file, sha1 = excluded.sha1,
|
||||||
document = excluded.document",
|
document = excluded.document",
|
||||||
)
|
)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(had_file)
|
.bind(had_file)
|
||||||
.bind(sha1)
|
.bind(sha1)
|
||||||
.bind(bytes)
|
.bind(bytes)
|
||||||
|
|||||||
+8
-8
@@ -124,10 +124,10 @@ pub(super) async fn read_instance_changes_into_shared_settings(
|
|||||||
.bind(canonical_type)
|
.bind(canonical_type)
|
||||||
.bind(value_json)
|
.bind(value_json)
|
||||||
.bind(next_revision)
|
.bind(next_revision)
|
||||||
.bind(metadata.applied_content_set.game_version)
|
.bind(&metadata.applied_content_set.game_version)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.bind(option_id)
|
.bind(&option_id)
|
||||||
.bind(current_revision)
|
.bind(current_revision)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -209,7 +209,7 @@ pub(super) async fn discover_custom_settings(
|
|||||||
)
|
)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.bind(custom_id)
|
.bind(&custom_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -218,7 +218,7 @@ pub(super) async fn discover_custom_settings(
|
|||||||
WHERE option_id = ?",
|
WHERE option_id = ?",
|
||||||
)
|
)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(custom_id)
|
.bind(&custom_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
discovered = true;
|
discovered = true;
|
||||||
@@ -254,7 +254,7 @@ pub(super) async fn discover_custom_settings(
|
|||||||
.bind(canonical_type)
|
.bind(canonical_type)
|
||||||
.bind(value_json)
|
.bind(value_json)
|
||||||
.bind(game_version)
|
.bind(game_version)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -320,12 +320,12 @@ pub(super) async fn discover_custom_settings(
|
|||||||
source_instance_id = excluded.source_instance_id,
|
source_instance_id = excluded.source_instance_id,
|
||||||
updated_at = excluded.updated_at",
|
updated_at = excluded.updated_at",
|
||||||
)
|
)
|
||||||
.bind(option_id)
|
.bind(&option_id)
|
||||||
.bind(key)
|
.bind(key)
|
||||||
.bind(value_json)
|
.bind(value_json)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(game_version)
|
.bind(game_version)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -436,7 +436,7 @@ pub async fn save_changes(
|
|||||||
source_game_version = NULL, source_instance_id = NULL,
|
source_game_version = NULL, source_instance_id = NULL,
|
||||||
updated_at = excluded.updated_at",
|
updated_at = excluded.updated_at",
|
||||||
)
|
)
|
||||||
.bind(setting.option_id)
|
.bind(&setting.option_id)
|
||||||
.bind(kind)
|
.bind(kind)
|
||||||
.bind(raw_key)
|
.bind(raw_key)
|
||||||
.bind(canonical_type)
|
.bind(canonical_type)
|
||||||
@@ -457,7 +457,7 @@ pub async fn save_changes(
|
|||||||
)
|
)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.bind(setting.option_id)
|
.bind(&setting.option_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -471,7 +471,7 @@ pub async fn save_changes(
|
|||||||
enabled = excluded.enabled, source = 'user',
|
enabled = excluded.enabled, source = 'user',
|
||||||
revision = excluded.revision",
|
revision = excluded.revision",
|
||||||
)
|
)
|
||||||
.bind(setting.option_id)
|
.bind(&setting.option_id)
|
||||||
.bind(enabled)
|
.bind(enabled)
|
||||||
.bind("user")
|
.bind("user")
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
|||||||
)
|
)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(now)
|
.bind(now)
|
||||||
.bind(custom_id)
|
.bind(&custom_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -109,7 +109,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
|||||||
WHERE option_id = ?",
|
WHERE option_id = ?",
|
||||||
)
|
)
|
||||||
.bind(revision)
|
.bind(revision)
|
||||||
.bind(custom_id)
|
.bind(&custom_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
|||||||
source_instance_id = excluded.source_instance_id,
|
source_instance_id = excluded.source_instance_id,
|
||||||
updated_at = excluded.updated_at",
|
updated_at = excluded.updated_at",
|
||||||
)
|
)
|
||||||
.bind(option_id)
|
.bind(&option_id)
|
||||||
.bind(key)
|
.bind(key)
|
||||||
.bind(value_json)
|
.bind(value_json)
|
||||||
.bind(option_revision)
|
.bind(option_revision)
|
||||||
@@ -261,7 +261,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
|||||||
ON CONFLICT(option_id) DO NOTHING
|
ON CONFLICT(option_id) DO NOTHING
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(option_id)
|
.bind(&option_id)
|
||||||
.bind(option_revision)
|
.bind(option_revision)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ use super::files::{
|
|||||||
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
||||||
finish_checkpoint, instance_game_dir, nbt_from_bytes, nbt_to_bytes,
|
finish_checkpoint, instance_game_dir, nbt_from_bytes, nbt_to_bytes,
|
||||||
read_nbt_file, safe_instance_id, sha1_bytes, sha1_file,
|
read_nbt_file, safe_instance_id, sha1_bytes, sha1_file,
|
||||||
|
synced_options_path,
|
||||||
};
|
};
|
||||||
use super::orchestration::{
|
use super::orchestration::{
|
||||||
backup_bytes, create_synced_directories, option_effective,
|
backup_bytes, create_synced_directories, option_effective,
|
||||||
seed_from_instance, synced_options_path,
|
seed_from_instance,
|
||||||
};
|
};
|
||||||
use crate::state::{InstanceMetadata, SyncedOption};
|
use crate::state::{InstanceMetadata, SyncedOption};
|
||||||
use crate::util::io;
|
use crate::util::io;
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ pub(super) use self::files::{
|
|||||||
pub(super) use self::orchestration::instance_option_supported;
|
pub(super) use self::orchestration::instance_option_supported;
|
||||||
pub use self::orchestration::{
|
pub use self::orchestration::{
|
||||||
GlobalSyncedOptions, SyncedOptionCapability, SyncedOptionJoinAction,
|
GlobalSyncedOptions, SyncedOptionCapability, SyncedOptionJoinAction,
|
||||||
SyncedOptionJoinPreview, SyncedOptionJoinResolution, SyncedOptionsOverview,
|
SyncedOptionJoinPreview, SyncedOptionsOverview, get_capabilities,
|
||||||
get_capabilities, get_global_options, get_initialized_options,
|
get_global_options, get_initialized_options,
|
||||||
get_instance_option_join_preview, get_overview, get_synced_options_folder,
|
get_instance_option_join_preview, get_overview, get_synced_options_folder,
|
||||||
reconcile_all, reconcile_changed_file, reconcile_instance,
|
reconcile_all, reconcile_changed_file, reconcile_instance,
|
||||||
set_global_option, set_instance_option,
|
set_global_option, set_instance_option,
|
||||||
@@ -30,3 +30,4 @@ pub(crate) use self::orchestration::{
|
|||||||
reconcile_instance_after_pack_update_with_state,
|
reconcile_instance_after_pack_update_with_state,
|
||||||
remove_generated_instance_files,
|
remove_generated_instance_files,
|
||||||
};
|
};
|
||||||
|
pub use self::pending::SyncedOptionJoinResolution;
|
||||||
@@ -5,7 +5,7 @@ use super::operations::{compose_instance, effective};
|
|||||||
use super::storage::{load_local, write_local_rows};
|
use super::storage::{load_local, write_local_rows};
|
||||||
use super::types::{LocalServer, ServerSource};
|
use super::types::{LocalServer, ServerSource};
|
||||||
use crate::state::{CachedEntry, InstanceLink, InstanceMetadata};
|
use crate::state::{CachedEntry, InstanceLink, InstanceMetadata};
|
||||||
use crate::util::fetch::{DownloadMeta, DownloadReason, fetch};
|
use crate::util::fetch::fetch;
|
||||||
use crate::{ErrorKind, State};
|
use crate::{ErrorKind, State};
|
||||||
use async_zip::base::read::seek::ZipFileReader;
|
use async_zip::base::read::seek::ZipFileReader;
|
||||||
use quartz_nbt::NbtCompound;
|
use quartz_nbt::NbtCompound;
|
||||||
@@ -74,7 +74,7 @@ async fn replace_modpack_servers(
|
|||||||
ON CONFLICT(instance_id) DO UPDATE SET
|
ON CONFLICT(instance_id) DO UPDATE SET
|
||||||
version_id = excluded.version_id",
|
version_id = excluded.version_id",
|
||||||
)
|
)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.bind(version_id)
|
.bind(version_id)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -91,7 +91,7 @@ pub(super) async fn pack_state_matches_link(
|
|||||||
FROM instance_server_pack_state
|
FROM instance_server_pack_state
|
||||||
WHERE instance_id = ?",
|
WHERE instance_id = ?",
|
||||||
)
|
)
|
||||||
.bind(metadata.instance.id)
|
.bind(&metadata.instance.id)
|
||||||
.fetch_optional(&state.pool)
|
.fetch_optional(&state.pool)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(row.is_some_and(|row| {
|
Ok(row.is_some_and(|row| {
|
||||||
@@ -149,16 +149,9 @@ pub(super) async fn reconstruct_modpack_servers(
|
|||||||
"Modpack version {version_id} has no downloadable file"
|
"Modpack version {version_id} has no downloadable file"
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
let download_meta = DownloadMeta {
|
|
||||||
reason: DownloadReason::Modpack,
|
|
||||||
game_version: metadata.applied_content_set.game_version.clone(),
|
|
||||||
loader: metadata.applied_content_set.loader.as_str().to_string(),
|
|
||||||
dependent_on: Some(version_id.to_string()),
|
|
||||||
};
|
|
||||||
let mrpack = fetch(
|
let mrpack = fetch(
|
||||||
&primary_file.url,
|
&primary_file.url,
|
||||||
primary_file.hashes.get("sha1").map(String::as_str),
|
primary_file.hashes.get("sha1").map(String::as_str),
|
||||||
Some(&download_meta),
|
|
||||||
None,
|
None,
|
||||||
&state.api_semaphore,
|
&state.api_semaphore,
|
||||||
&state.pool,
|
&state.pool,
|
||||||
|
|||||||
@@ -120,11 +120,13 @@ async fn write_canonical_rows(
|
|||||||
nbt_to_bytes(&server.data)?,
|
nbt_to_bytes(&server.data)?,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
use sqlx::Row;
|
||||||
if current.len() == desired.len()
|
if current.len() == desired.len()
|
||||||
&& current.iter().zip(&desired).all(|(current, desired)| {
|
&& current.iter().zip(&desired).all(|(current, desired)| {
|
||||||
current.id == desired.0
|
let id: String = current.get("id");
|
||||||
&& current.position == desired.1
|
let position: i64 = current.get("position");
|
||||||
&& current.nbt == desired.2
|
let nbt: Vec<u8> = current.get("nbt");
|
||||||
|
id == desired.0 && position == desired.1 && nbt == desired.2
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
@@ -133,9 +135,10 @@ async fn write_canonical_rows(
|
|||||||
let desired_ids =
|
let desired_ids =
|
||||||
desired.iter().map(|(id, _, _)| *id).collect::<HashSet<_>>();
|
desired.iter().map(|(id, _, _)| *id).collect::<HashSet<_>>();
|
||||||
for row in ¤t {
|
for row in ¤t {
|
||||||
if !desired_ids.contains(row.id.as_str()) {
|
let row_id: String = row.get("id");
|
||||||
|
if !desired_ids.contains(row_id.as_str()) {
|
||||||
sqlx::query("DELETE FROM synced_servers WHERE id = ?")
|
sqlx::query("DELETE FROM synced_servers WHERE id = ?")
|
||||||
.bind(&row.id)
|
.bind(&row_id)
|
||||||
.execute(&mut **tx)
|
.execute(&mut **tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
@@ -143,7 +146,10 @@ async fn write_canonical_rows(
|
|||||||
|
|
||||||
let position_offset = current
|
let position_offset = current
|
||||||
.iter()
|
.iter()
|
||||||
.map(|row| row.position)
|
.map(|row| {
|
||||||
|
let p: i64 = row.get("position");
|
||||||
|
p
|
||||||
|
})
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
.max(servers.len() as i64)
|
.max(servers.len() as i64)
|
||||||
|
|||||||
@@ -948,6 +948,8 @@ impl State {
|
|||||||
configured_http_client: RwLock::new(configured_http_client),
|
configured_http_client: RwLock::new(configured_http_client),
|
||||||
configured_http_client_update: AsyncMutex::new(()),
|
configured_http_client_update: AsyncMutex::new(()),
|
||||||
file_watcher,
|
file_watcher,
|
||||||
|
synced_options_lock: Arc::new(AsyncMutex::new(())),
|
||||||
|
game_locale_indexer: Default::default(),
|
||||||
// app_identifier,
|
// app_identifier,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user