fix: resolve missing imports and incorrect mutable references in save and update modes
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -3,6 +3,9 @@ use clap::Command;
|
|||||||
use log::debug;
|
use log::debug;
|
||||||
use std::io::{Read, Write, IsTerminal};
|
use std::io::{Read, Write, IsTerminal};
|
||||||
|
|
||||||
|
// Import the missing functions from common module
|
||||||
|
use crate::modes::common::{cmd_args_digest_type, cmd_args_compression_type, cmd_args_meta_plugin_types};
|
||||||
|
|
||||||
fn validate_save_args(cmd: &mut Command, ids: &Vec<i64>) {
|
fn validate_save_args(cmd: &mut Command, ids: &Vec<i64>) {
|
||||||
if !ids.is_empty() {
|
if !ids.is_empty() {
|
||||||
cmd.error(
|
cmd.error(
|
||||||
@@ -21,18 +24,18 @@ fn initialize_tags(tags: &mut Vec<String>) {
|
|||||||
|
|
||||||
fn setup_compression_and_plugins(
|
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
|
||||||
@@ -117,7 +120,7 @@ fn create_and_log_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup_item_metadata(
|
fn setup_item_metadata(
|
||||||
conn: &rusqlite::Connection,
|
conn: &mut rusqlite::Connection, // Changed to mutable reference
|
||||||
args: &crate::Args,
|
args: &crate::Args,
|
||||||
item: &crate::db::Item,
|
item: &crate::db::Item,
|
||||||
tags: &Vec<String>,
|
tags: &Vec<String>,
|
||||||
@@ -199,7 +202,7 @@ fn process_input_stream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize_meta_plugins(
|
fn finalize_meta_plugins(
|
||||||
conn: &rusqlite::Connection,
|
conn: &mut rusqlite::Connection, // Changed to mutable reference
|
||||||
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> {
|
||||||
@@ -234,7 +237,7 @@ pub fn mode_save(
|
|||||||
let (compression_type, compression_engine, mut meta_plugins) = setup_compression_and_plugins(cmd, args);
|
let (compression_type, compression_engine, mut meta_plugins) = setup_compression_and_plugins(cmd, args);
|
||||||
|
|
||||||
let mut item = create_and_log_item(conn, args, tags, &compression_type)?;
|
let mut item = create_and_log_item(conn, args, tags, &compression_type)?;
|
||||||
setup_item_metadata(conn, args, &item, tags)?;
|
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 tx = conn.transaction()?;
|
||||||
@@ -261,7 +264,8 @@ 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();
|
||||||
|
|
||||||
finalize_meta_plugins(&mut tx.into_inner(), &mut meta_plugins, &item)?;
|
// Pass the transaction as mutable reference directly
|
||||||
|
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
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ pub fn mode_update(
|
|||||||
debug!("DIGEST: {}", digest_value);
|
debug!("DIGEST: {}", digest_value);
|
||||||
|
|
||||||
// Save digest to meta using the common function
|
// Save digest to meta using the common function
|
||||||
store_item_digest_value(&mut tx.into_inner(), item.clone(), digest_type, digest_value)?;
|
// Pass the transaction directly instead of calling into_inner()
|
||||||
|
store_item_digest_value(&tx, item.clone(), digest_type, digest_value)?;
|
||||||
} 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