fix: correct variable name and mutable transaction handling in save and update modes
Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
@@ -26,16 +26,16 @@ fn setup_compression_and_plugins(
|
|||||||
cmd: &mut Command,
|
cmd: &mut Command,
|
||||||
args: &crate::Args,
|
args: &crate::Args,
|
||||||
) -> (crate::compression_engine::CompressionType, Box<dyn crate::compression_engine::CompressionEngine>, Vec<Box<dyn crate::meta_plugin::MetaPlugin>>) {
|
) -> (crate::compression_engine::CompressionType, Box<dyn crate::compression_engine::CompressionEngine>, Vec<Box<dyn crate::meta_plugin::MetaPlugin>>) {
|
||||||
let digest_type = cmd_args_digest_type(cmd, &_args);
|
let digest_type = cmd_args_digest_type(cmd, &args);
|
||||||
debug!("MAIN: Digest type: {:?}", digest_type);
|
debug!("MAIN: Digest type: {:?}", digest_type);
|
||||||
|
|
||||||
let compression_type = cmd_args_compression_type(cmd, &_args);
|
let compression_type = cmd_args_compression_type(cmd, &args);
|
||||||
debug!("MAIN: Compression type: {:?}", compression_type);
|
debug!("MAIN: Compression type: {:?}", compression_type);
|
||||||
let compression_engine =
|
let compression_engine =
|
||||||
crate::compression_engine::get_compression_engine(compression_type.clone()).expect("Unable to get compression engine");
|
crate::compression_engine::get_compression_engine(compression_type.clone()).expect("Unable to get compression engine");
|
||||||
|
|
||||||
// Start with meta plugin types from command line
|
// Start with meta plugin types from command line
|
||||||
let mut meta_plugin_types: Vec<crate::meta_plugin::MetaPluginType> = cmd_args_meta_plugin_types(cmd, &_args);
|
let mut meta_plugin_types: Vec<crate::meta_plugin::MetaPluginType> = cmd_args_meta_plugin_types(cmd, &args);
|
||||||
debug!("MAIN: Meta plugin types: {:?}", meta_plugin_types);
|
debug!("MAIN: Meta plugin types: {:?}", meta_plugin_types);
|
||||||
|
|
||||||
// Convert digest type to meta plugin type and add to the list if needed
|
// Convert digest type to meta plugin type and add to the list if needed
|
||||||
@@ -202,7 +202,7 @@ fn process_input_stream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_meta_plugins(
|
fn finalize_meta_plugins(
|
||||||
conn: &mut rusqlite::Connection,
|
conn: &rusqlite::Connection,
|
||||||
meta_plugins: &mut Vec<Box<dyn crate::meta_plugin::MetaPlugin>>,
|
meta_plugins: &mut Vec<Box<dyn crate::meta_plugin::MetaPlugin>>,
|
||||||
item: &crate::db::Item,
|
item: &crate::db::Item,
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
@@ -211,7 +211,12 @@ fn finalize_meta_plugins(
|
|||||||
|
|
||||||
match meta_plugin.finalize() {
|
match meta_plugin.finalize() {
|
||||||
Ok(meta_value) => {
|
Ok(meta_value) => {
|
||||||
if let Err(e) = crate::modes::common::store_item_meta_value(conn, item.clone(), meta_name.clone(), meta_value) {
|
let meta = crate::db::Meta {
|
||||||
|
id: item.id.ok_or_else(|| anyhow!("Item missing ID"))?,
|
||||||
|
name: meta_name.clone(),
|
||||||
|
value: meta_value,
|
||||||
|
};
|
||||||
|
if let Err(e) = crate::db::store_meta(conn, meta) {
|
||||||
eprintln!("Warning: Failed to store meta value for {}: {}", meta_name, e);
|
eprintln!("Warning: Failed to store meta value for {}: {}", meta_name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -240,7 +245,7 @@ pub fn mode_save(
|
|||||||
setup_item_metadata(conn, args, &item, tags)?; // Pass mutable reference
|
setup_item_metadata(conn, args, &item, tags)?; // Pass mutable reference
|
||||||
|
|
||||||
// Use a transaction for database operations to ensure atomicity
|
// Use a transaction for database operations to ensure atomicity
|
||||||
let tx = conn.transaction()?;
|
let mut tx = conn.transaction()?;
|
||||||
|
|
||||||
let item_meta = collect_item_meta(args);
|
let item_meta = collect_item_meta(args);
|
||||||
let item_id = item.id.ok_or_else(|| anyhow!("Item missing ID"))?;
|
let item_id = item.id.ok_or_else(|| anyhow!("Item missing ID"))?;
|
||||||
@@ -264,8 +269,7 @@ pub fn mode_save(
|
|||||||
item.size = processed_item.size;
|
item.size = processed_item.size;
|
||||||
item.compression = compression_type.to_string();
|
item.compression = compression_type.to_string();
|
||||||
|
|
||||||
// Pass the transaction as mutable reference
|
finalize_meta_plugins(&tx, &mut meta_plugins, &item)?;
|
||||||
finalize_meta_plugins(&mut tx, &mut meta_plugins, &item)?;
|
|
||||||
crate::db::update_item(&tx, item.clone())?;
|
crate::db::update_item(&tx, item.clone())?;
|
||||||
|
|
||||||
// Commit the transaction
|
// Commit the transaction
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub fn mode_update(
|
|||||||
debug!("MAIN: Found item {:?}", item);
|
debug!("MAIN: Found item {:?}", item);
|
||||||
|
|
||||||
// Use a transaction for database operations to ensure atomicity
|
// Use a transaction for database operations to ensure atomicity
|
||||||
let tx = conn.transaction()?;
|
let mut tx = conn.transaction()?;
|
||||||
|
|
||||||
if !tags.is_empty() {
|
if !tags.is_empty() {
|
||||||
debug!("MAIN: Updating item tags");
|
debug!("MAIN: Updating item tags");
|
||||||
@@ -99,9 +99,14 @@ pub fn mode_update(
|
|||||||
let digest_value = digest_engine.finalize()?;
|
let digest_value = digest_engine.finalize()?;
|
||||||
debug!("DIGEST: {}", digest_value);
|
debug!("DIGEST: {}", digest_value);
|
||||||
|
|
||||||
// Save digest to meta using the common function
|
// Save digest to meta
|
||||||
// Pass the transaction as mutable reference
|
let digest_meta_name = get_digest_type_meta(digest_type);
|
||||||
store_item_digest_value(&mut tx, item.clone(), digest_type, digest_value)?;
|
let digest_meta = db::Meta {
|
||||||
|
id: item_id,
|
||||||
|
name: digest_meta_name,
|
||||||
|
value: digest_value,
|
||||||
|
};
|
||||||
|
db::store_meta(&tx, digest_meta)?;
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
"MAIN: Unable to update digest of item due to missing file {:?}",
|
"MAIN: Unable to update digest of item due to missing file {:?}",
|
||||||
|
|||||||
Reference in New Issue
Block a user