pinakes-core: emit plugin events from scan and import pipelines

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib992e292a3272c52f9b7c18164ec61f56a6a6964
This commit is contained in:
raf 2026-03-08 15:01:46 +03:00
commit f686e8a777
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 83 additions and 12 deletions

View file

@ -11,7 +11,12 @@ use notify::{PollWatcher, RecursiveMode, Watcher};
use tokio::sync::mpsc;
use tracing::{info, warn};
use crate::{error::Result, import, storage::DynStorageBackend};
use crate::{
error::Result,
import,
plugin::PluginPipeline,
storage::DynStorageBackend,
};
/// Status of a directory scan operation.
pub struct ScanStatus {
@ -122,6 +127,7 @@ pub async fn scan_directory(
storage: &DynStorageBackend,
dir: &Path,
ignore_patterns: &[String],
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<ScanStatus> {
scan_directory_with_options(
storage,
@ -129,6 +135,7 @@ pub async fn scan_directory(
ignore_patterns,
None,
&ScanOptions::default(),
pipeline,
)
.await
}
@ -154,13 +161,21 @@ pub async fn scan_directory_incremental(
storage: &DynStorageBackend,
dir: &Path,
ignore_patterns: &[String],
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<ScanStatus> {
let options = ScanOptions {
incremental: true,
force_full: false,
};
scan_directory_with_options(storage, dir, ignore_patterns, None, &options)
.await
scan_directory_with_options(
storage,
dir,
ignore_patterns,
None,
&options,
pipeline,
)
.await
}
/// Scans a directory with progress reporting.
@ -184,6 +199,7 @@ pub async fn scan_directory_with_progress(
dir: &Path,
ignore_patterns: &[String],
progress: Option<&ScanProgress>,
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<ScanStatus> {
scan_directory_with_options(
storage,
@ -191,6 +207,7 @@ pub async fn scan_directory_with_progress(
ignore_patterns,
progress,
&ScanOptions::default(),
pipeline,
)
.await
}
@ -207,6 +224,7 @@ pub async fn scan_directory_with_options(
ignore_patterns: &[String],
progress: Option<&ScanProgress>,
scan_options: &ScanOptions,
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<ScanStatus> {
info!(
dir = %dir.display(),
@ -230,8 +248,9 @@ pub async fn scan_directory_with_options(
storage,
dir,
ignore_patterns,
8, // Default concurrency
8, // default concurrency
&import_options,
pipeline,
)
.await?;
@ -301,12 +320,14 @@ pub async fn scan_directory_with_options(
pub async fn scan_all_roots(
storage: &DynStorageBackend,
ignore_patterns: &[String],
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<Vec<ScanStatus>> {
scan_all_roots_with_options(
storage,
ignore_patterns,
None,
&ScanOptions::default(),
pipeline,
)
.await
}
@ -328,12 +349,20 @@ pub async fn scan_all_roots(
pub async fn scan_all_roots_incremental(
storage: &DynStorageBackend,
ignore_patterns: &[String],
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<Vec<ScanStatus>> {
let options = ScanOptions {
incremental: true,
force_full: false,
};
scan_all_roots_with_options(storage, ignore_patterns, None, &options).await
scan_all_roots_with_options(
storage,
ignore_patterns,
None,
&options,
pipeline,
)
.await
}
/// Scans all root directories with progress reporting.
@ -355,12 +384,14 @@ pub async fn scan_all_roots_with_progress(
storage: &DynStorageBackend,
ignore_patterns: &[String],
progress: Option<&ScanProgress>,
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<Vec<ScanStatus>> {
scan_all_roots_with_options(
storage,
ignore_patterns,
progress,
&ScanOptions::default(),
pipeline,
)
.await
}
@ -386,6 +417,7 @@ pub async fn scan_all_roots_with_options(
ignore_patterns: &[String],
progress: Option<&ScanProgress>,
scan_options: &ScanOptions,
pipeline: Option<&Arc<PluginPipeline>>,
) -> Result<Vec<ScanStatus>> {
let roots = storage.list_root_dirs().await?;
let mut statuses = Vec::new();
@ -397,6 +429,7 @@ pub async fn scan_all_roots_with_options(
ignore_patterns,
progress,
scan_options,
pipeline,
)
.await
{
@ -536,7 +569,7 @@ pub async fn watch_and_import(
&& !crate::import::should_ignore(&path, &ignore_patterns)
{
info!(path = %path.display(), "detected file change, importing");
if let Err(e) = import::import_file(&storage, &path).await {
if let Err(e) = import::import_file(&storage, &path, None).await {
warn!(path = %path.display(), error = %e, "failed to import changed file");
}
}