- 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::{
|
||||
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
||||
finish_checkpoint, instance_game_dir, sha1_bytes, sha1_file,
|
||||
synced_options_path,
|
||||
};
|
||||
use super::orchestration::{
|
||||
create_synced_directories, option_effective, synced_options_path,
|
||||
};
|
||||
use super::orchestration::{create_synced_directories, option_effective};
|
||||
use crate::State;
|
||||
use crate::state::{InstanceMetadata, SyncedOption};
|
||||
use crate::util::io;
|
||||
|
||||
@@ -134,7 +134,7 @@ pub(in crate::api::instance) async fn detach_instance(
|
||||
"DELETE FROM instance_sync_checkpoints
|
||||
WHERE instance_id = ? AND feature = ?",
|
||||
)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(feature)
|
||||
.execute(&state.pool)
|
||||
.await?;
|
||||
@@ -150,7 +150,7 @@ pub(in crate::api::instance) async fn prepare_instance_update_with_state(
|
||||
sqlx::query(
|
||||
"DELETE FROM instance_game_option_update_state WHERE instance_id = ?",
|
||||
)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.execute(&state.pool)
|
||||
.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,
|
||||
document = excluded.document",
|
||||
)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(had_file)
|
||||
.bind(sha1)
|
||||
.bind(bytes)
|
||||
|
||||
+8
-8
@@ -124,10 +124,10 @@ pub(super) async fn read_instance_changes_into_shared_settings(
|
||||
.bind(canonical_type)
|
||||
.bind(value_json)
|
||||
.bind(next_revision)
|
||||
.bind(metadata.applied_content_set.game_version)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.applied_content_set.game_version)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(now)
|
||||
.bind(option_id)
|
||||
.bind(&option_id)
|
||||
.bind(current_revision)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
@@ -209,7 +209,7 @@ pub(super) async fn discover_custom_settings(
|
||||
)
|
||||
.bind(revision)
|
||||
.bind(now)
|
||||
.bind(custom_id)
|
||||
.bind(&custom_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
sqlx::query(
|
||||
@@ -218,7 +218,7 @@ pub(super) async fn discover_custom_settings(
|
||||
WHERE option_id = ?",
|
||||
)
|
||||
.bind(revision)
|
||||
.bind(custom_id)
|
||||
.bind(&custom_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
discovered = true;
|
||||
@@ -254,7 +254,7 @@ pub(super) async fn discover_custom_settings(
|
||||
.bind(canonical_type)
|
||||
.bind(value_json)
|
||||
.bind(game_version)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
@@ -320,12 +320,12 @@ pub(super) async fn discover_custom_settings(
|
||||
source_instance_id = excluded.source_instance_id,
|
||||
updated_at = excluded.updated_at",
|
||||
)
|
||||
.bind(option_id)
|
||||
.bind(&option_id)
|
||||
.bind(key)
|
||||
.bind(value_json)
|
||||
.bind(revision)
|
||||
.bind(game_version)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(now)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
@@ -436,7 +436,7 @@ pub async fn save_changes(
|
||||
source_game_version = NULL, source_instance_id = NULL,
|
||||
updated_at = excluded.updated_at",
|
||||
)
|
||||
.bind(setting.option_id)
|
||||
.bind(&setting.option_id)
|
||||
.bind(kind)
|
||||
.bind(raw_key)
|
||||
.bind(canonical_type)
|
||||
@@ -457,7 +457,7 @@ pub async fn save_changes(
|
||||
)
|
||||
.bind(revision)
|
||||
.bind(now)
|
||||
.bind(setting.option_id)
|
||||
.bind(&setting.option_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
@@ -471,7 +471,7 @@ pub async fn save_changes(
|
||||
enabled = excluded.enabled, source = 'user',
|
||||
revision = excluded.revision",
|
||||
)
|
||||
.bind(setting.option_id)
|
||||
.bind(&setting.option_id)
|
||||
.bind(enabled)
|
||||
.bind("user")
|
||||
.bind(revision)
|
||||
|
||||
@@ -100,7 +100,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
||||
)
|
||||
.bind(revision)
|
||||
.bind(now)
|
||||
.bind(custom_id)
|
||||
.bind(&custom_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
sqlx::query(
|
||||
@@ -109,7 +109,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
||||
WHERE option_id = ?",
|
||||
)
|
||||
.bind(revision)
|
||||
.bind(custom_id)
|
||||
.bind(&custom_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
||||
source_instance_id = excluded.source_instance_id,
|
||||
updated_at = excluded.updated_at",
|
||||
)
|
||||
.bind(option_id)
|
||||
.bind(&option_id)
|
||||
.bind(key)
|
||||
.bind(value_json)
|
||||
.bind(option_revision)
|
||||
@@ -261,7 +261,7 @@ pub(in crate::api::instance) async fn initialize_from_source_instance(
|
||||
ON CONFLICT(option_id) DO NOTHING
|
||||
",
|
||||
)
|
||||
.bind(option_id)
|
||||
.bind(&option_id)
|
||||
.bind(option_revision)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
@@ -3,10 +3,11 @@ use super::files::{
|
||||
CheckpointStatus, begin_checkpoint, checkpoint, ensure_link,
|
||||
finish_checkpoint, instance_game_dir, nbt_from_bytes, nbt_to_bytes,
|
||||
read_nbt_file, safe_instance_id, sha1_bytes, sha1_file,
|
||||
synced_options_path,
|
||||
};
|
||||
use super::orchestration::{
|
||||
backup_bytes, create_synced_directories, option_effective,
|
||||
seed_from_instance, synced_options_path,
|
||||
seed_from_instance,
|
||||
};
|
||||
use crate::state::{InstanceMetadata, SyncedOption};
|
||||
use crate::util::io;
|
||||
|
||||
@@ -19,8 +19,8 @@ pub(super) use self::files::{
|
||||
pub(super) use self::orchestration::instance_option_supported;
|
||||
pub use self::orchestration::{
|
||||
GlobalSyncedOptions, SyncedOptionCapability, SyncedOptionJoinAction,
|
||||
SyncedOptionJoinPreview, SyncedOptionJoinResolution, SyncedOptionsOverview,
|
||||
get_capabilities, get_global_options, get_initialized_options,
|
||||
SyncedOptionJoinPreview, SyncedOptionsOverview, get_capabilities,
|
||||
get_global_options, get_initialized_options,
|
||||
get_instance_option_join_preview, get_overview, get_synced_options_folder,
|
||||
reconcile_all, reconcile_changed_file, reconcile_instance,
|
||||
set_global_option, set_instance_option,
|
||||
@@ -30,3 +30,4 @@ pub(crate) use self::orchestration::{
|
||||
reconcile_instance_after_pack_update_with_state,
|
||||
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::types::{LocalServer, ServerSource};
|
||||
use crate::state::{CachedEntry, InstanceLink, InstanceMetadata};
|
||||
use crate::util::fetch::{DownloadMeta, DownloadReason, fetch};
|
||||
use crate::util::fetch::fetch;
|
||||
use crate::{ErrorKind, State};
|
||||
use async_zip::base::read::seek::ZipFileReader;
|
||||
use quartz_nbt::NbtCompound;
|
||||
@@ -74,7 +74,7 @@ async fn replace_modpack_servers(
|
||||
ON CONFLICT(instance_id) DO UPDATE SET
|
||||
version_id = excluded.version_id",
|
||||
)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.bind(version_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
@@ -91,7 +91,7 @@ pub(super) async fn pack_state_matches_link(
|
||||
FROM instance_server_pack_state
|
||||
WHERE instance_id = ?",
|
||||
)
|
||||
.bind(metadata.instance.id)
|
||||
.bind(&metadata.instance.id)
|
||||
.fetch_optional(&state.pool)
|
||||
.await?;
|
||||
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"
|
||||
))
|
||||
})?;
|
||||
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(
|
||||
&primary_file.url,
|
||||
primary_file.hashes.get("sha1").map(String::as_str),
|
||||
Some(&download_meta),
|
||||
None,
|
||||
&state.api_semaphore,
|
||||
&state.pool,
|
||||
|
||||
@@ -120,11 +120,13 @@ async fn write_canonical_rows(
|
||||
nbt_to_bytes(&server.data)?,
|
||||
));
|
||||
}
|
||||
use sqlx::Row;
|
||||
if current.len() == desired.len()
|
||||
&& current.iter().zip(&desired).all(|(current, desired)| {
|
||||
current.id == desired.0
|
||||
&& current.position == desired.1
|
||||
&& current.nbt == desired.2
|
||||
let id: String = current.get("id");
|
||||
let position: i64 = current.get("position");
|
||||
let nbt: Vec<u8> = current.get("nbt");
|
||||
id == desired.0 && position == desired.1 && nbt == desired.2
|
||||
})
|
||||
{
|
||||
return Ok(false);
|
||||
@@ -133,9 +135,10 @@ async fn write_canonical_rows(
|
||||
let desired_ids =
|
||||
desired.iter().map(|(id, _, _)| *id).collect::<HashSet<_>>();
|
||||
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 = ?")
|
||||
.bind(&row.id)
|
||||
.bind(&row_id)
|
||||
.execute(&mut **tx)
|
||||
.await?;
|
||||
}
|
||||
@@ -143,7 +146,10 @@ async fn write_canonical_rows(
|
||||
|
||||
let position_offset = current
|
||||
.iter()
|
||||
.map(|row| row.position)
|
||||
.map(|row| {
|
||||
let p: i64 = row.get("position");
|
||||
p
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(0)
|
||||
.max(servers.len() as i64)
|
||||
|
||||
@@ -948,6 +948,8 @@ impl State {
|
||||
configured_http_client: RwLock::new(configured_http_client),
|
||||
configured_http_client_update: AsyncMutex::new(()),
|
||||
file_watcher,
|
||||
synced_options_lock: Arc::new(AsyncMutex::new(())),
|
||||
game_locale_indexer: Default::default(),
|
||||
// app_identifier,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user