refactor: decouple meta plugins from DB via SaveMetaFn callback, extract shared utilities
- Add SaveMetaFn callback pattern: meta plugins receive a closure instead of
&Connection, enabling the same plugin code to work in local, client, and
server contexts (collect-to-Vec, collect-to-HashMap, or direct DB write)
- Client save now runs meta plugins locally during streaming (smart client
sets meta=false, server skips its own plugins)
- Add POST /api/item/{id}/update endpoint for re-running plugins on stored
content without downloading compressed data
- Add client update mode (--update with --meta-plugin flags)
- Extract shared utilities: stream_copy, print_serialized, build_path_table,
ensure_default_tag to reduce duplication across modes
- Add upsert_tag for idempotent tag addition (INSERT OR IGNORE)
- Add warn logging on save_meta lock failure in BaseMetaPlugin and MetaService
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
/// This module provides functionality for comparing two items and displaying their
|
||||
/// differences using external diff tools. Decompressed content is streamed to diff
|
||||
/// via pipes and /dev/fd file descriptors — no temporary files are created.
|
||||
use crate::common::PIPESIZE;
|
||||
use crate::config;
|
||||
use crate::services::compression_service::CompressionService;
|
||||
use crate::services::item_service::ItemService;
|
||||
@@ -118,17 +117,11 @@ fn spawn_writer_thread(
|
||||
|
||||
// Convert OwnedFd to File — safe, takes ownership, closes on drop
|
||||
let mut writer = std::fs::File::from(write_fd);
|
||||
let mut buf = [0u8; PIPESIZE];
|
||||
loop {
|
||||
match reader.read(&mut buf) {
|
||||
Ok(0) => break,
|
||||
Ok(n) => {
|
||||
use std::io::Write;
|
||||
writer.write_all(&buf[..n])?;
|
||||
}
|
||||
Err(e) => return Err(anyhow::anyhow!("Error reading item {item_id}: {e}")),
|
||||
}
|
||||
}
|
||||
crate::common::stream_copy(&mut reader, |chunk| {
|
||||
use std::io::Write;
|
||||
writer.write_all(chunk)
|
||||
})
|
||||
.map_err(|e| anyhow::anyhow!("Error reading item {item_id}: {e}"))?;
|
||||
// writer dropped here, closing write_fd → diff sees EOF
|
||||
Ok(())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user