pinakes-core: update remaining modules and tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I9e0ff5ea33a5cf697473423e88f167ce6a6a6964
This commit is contained in:
parent
c8425a4c34
commit
3d9f8933d2
44 changed files with 1207 additions and 578 deletions
|
|
@ -46,6 +46,7 @@ pub struct ScanProgress {
|
|||
const MAX_STORED_ERRORS: usize = 100;
|
||||
|
||||
impl ScanProgress {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
is_scanning: Arc::new(AtomicBool::new(false)),
|
||||
|
|
@ -56,6 +57,7 @@ impl ScanProgress {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn snapshot(&self) -> ScanStatus {
|
||||
let errors = self
|
||||
.error_messages
|
||||
|
|
@ -112,6 +114,10 @@ impl Default for ScanProgress {
|
|||
/// # Returns
|
||||
///
|
||||
/// Scan status with counts and any errors
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if the scan fails.
|
||||
pub async fn scan_directory(
|
||||
storage: &DynStorageBackend,
|
||||
dir: &Path,
|
||||
|
|
@ -140,6 +146,10 @@ pub async fn scan_directory(
|
|||
/// # Returns
|
||||
///
|
||||
/// Scan status with counts and any errors
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if the scan fails.
|
||||
pub async fn scan_directory_incremental(
|
||||
storage: &DynStorageBackend,
|
||||
dir: &Path,
|
||||
|
|
@ -165,6 +175,10 @@ pub async fn scan_directory_incremental(
|
|||
/// # Returns
|
||||
///
|
||||
/// Scan status with counts and any errors
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if the scan fails.
|
||||
pub async fn scan_directory_with_progress(
|
||||
storage: &DynStorageBackend,
|
||||
dir: &Path,
|
||||
|
|
@ -182,7 +196,11 @@ pub async fn scan_directory_with_progress(
|
|||
}
|
||||
|
||||
/// Scan a directory with full options including progress tracking and
|
||||
/// incremental mode
|
||||
/// incremental mode.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if the scan fails.
|
||||
pub async fn scan_directory_with_options(
|
||||
storage: &DynStorageBackend,
|
||||
dir: &Path,
|
||||
|
|
@ -276,6 +294,10 @@ pub async fn scan_directory_with_options(
|
|||
/// # Returns
|
||||
///
|
||||
/// Status for each root directory
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if listing roots or scanning fails.
|
||||
pub async fn scan_all_roots(
|
||||
storage: &DynStorageBackend,
|
||||
ignore_patterns: &[String],
|
||||
|
|
@ -299,6 +321,10 @@ pub async fn scan_all_roots(
|
|||
/// # Returns
|
||||
///
|
||||
/// Status for each root directory
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if listing roots or scanning fails.
|
||||
pub async fn scan_all_roots_incremental(
|
||||
storage: &DynStorageBackend,
|
||||
ignore_patterns: &[String],
|
||||
|
|
@ -321,6 +347,10 @@ pub async fn scan_all_roots_incremental(
|
|||
/// # Returns
|
||||
///
|
||||
/// Status for each root directory
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if listing roots or scanning fails.
|
||||
pub async fn scan_all_roots_with_progress(
|
||||
storage: &DynStorageBackend,
|
||||
ignore_patterns: &[String],
|
||||
|
|
@ -347,6 +377,10 @@ pub async fn scan_all_roots_with_progress(
|
|||
/// # Returns
|
||||
///
|
||||
/// Status for each root directory
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if listing roots or scanning fails.
|
||||
pub async fn scan_all_roots_with_options(
|
||||
storage: &DynStorageBackend,
|
||||
ignore_patterns: &[String],
|
||||
|
|
@ -391,6 +425,11 @@ pub struct FileWatcher {
|
|||
|
||||
impl FileWatcher {
|
||||
/// Creates a new file watcher for the given directories.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if no filesystem watcher could be
|
||||
/// created.
|
||||
pub fn new(dirs: &[PathBuf]) -> Result<Self> {
|
||||
let (tx, rx) = mpsc::channel(1024);
|
||||
|
||||
|
|
@ -419,7 +458,7 @@ impl FileWatcher {
|
|||
dirs: &[PathBuf],
|
||||
tx: mpsc::Sender<PathBuf>,
|
||||
) -> std::result::Result<Box<dyn Watcher + Send>, notify::Error> {
|
||||
let tx_clone = tx.clone();
|
||||
let tx_clone = tx;
|
||||
let mut watcher = notify::recommended_watcher(
|
||||
move |res: notify::Result<notify::Event>| {
|
||||
if let Ok(event) = res {
|
||||
|
|
@ -444,7 +483,7 @@ impl FileWatcher {
|
|||
dirs: &[PathBuf],
|
||||
tx: mpsc::Sender<PathBuf>,
|
||||
) -> Result<Box<dyn Watcher + Send>> {
|
||||
let tx_clone = tx.clone();
|
||||
let tx_clone = tx;
|
||||
let poll_interval = std::time::Duration::from_secs(5);
|
||||
let config = notify::Config::default().with_poll_interval(poll_interval);
|
||||
|
||||
|
|
@ -479,6 +518,10 @@ impl FileWatcher {
|
|||
}
|
||||
|
||||
/// Watches directories and imports files on change.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`crate::error::PinakesError`] if the watcher cannot be started.
|
||||
pub async fn watch_and_import(
|
||||
storage: DynStorageBackend,
|
||||
dirs: Vec<PathBuf>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue