Format codebase with rustfmt

This commit is contained in:
thePR0M3TH3AN
2025-05-21 11:24:49 -04:00
parent 9360efee2a
commit 567f1cd1a5
33 changed files with 780 additions and 481 deletions

View File

@@ -1,21 +1,21 @@
//! Database abstraction for Marlin
//!
//!
//! This module provides a database abstraction layer that wraps the SQLite connection
//! and provides methods for common database operations.
use anyhow::Result;
use rusqlite::Connection;
use std::path::PathBuf;
use anyhow::Result;
/// Options for indexing files
#[derive(Debug, Clone)]
pub struct IndexOptions {
/// Only update files marked as dirty
pub dirty_only: bool,
/// Index file contents (not just metadata)
pub index_contents: bool,
/// Maximum file size to index (in bytes)
pub max_size: Option<u64>,
}
@@ -41,32 +41,34 @@ impl Database {
pub fn new(conn: Connection) -> Self {
Self { conn }
}
/// Get a reference to the underlying connection
pub fn conn(&self) -> &Connection {
&self.conn
}
/// Get a mutable reference to the underlying connection
pub fn conn_mut(&mut self) -> &mut Connection {
&mut self.conn
}
/// Index one or more files
pub fn index_files(&mut self, paths: &[PathBuf], _options: &IndexOptions) -> Result<usize> {
// In a real implementation, this would index the files
// For now, we just return the number of files "indexed"
if paths.is_empty() { // Add a branch for coverage
if paths.is_empty() {
// Add a branch for coverage
return Ok(0);
}
Ok(paths.len())
}
/// Remove files from the index
pub fn remove_files(&mut self, paths: &[PathBuf]) -> Result<usize> {
// In a real implementation, this would remove the files
// For now, we just return the number of files "removed"
if paths.is_empty() { // Add a branch for coverage
if paths.is_empty() {
// Add a branch for coverage
return Ok(0);
}
Ok(paths.len())
@@ -77,8 +79,8 @@ impl Database {
mod tests {
use super::*;
use crate::db::open as open_marlin_db; // Use your project's DB open function
use tempfile::tempdir;
use std::fs::File;
use tempfile::tempdir;
fn setup_db() -> Database {
let conn = open_marlin_db(":memory:").expect("Failed to open in-memory DB");
@@ -102,7 +104,7 @@ mod tests {
let paths = vec![file1.to_path_buf()];
let options = IndexOptions::default();
assert_eq!(db.index_files(&paths, &options).unwrap(), 1);
assert_eq!(db.index_files(&[], &options).unwrap(), 0); // Test empty case
}
@@ -115,7 +117,7 @@ mod tests {
File::create(&file1).unwrap(); // File doesn't need to be in DB for this stub
let paths = vec![file1.to_path_buf()];
assert_eq!(db.remove_files(&paths).unwrap(), 1);
assert_eq!(db.remove_files(&[]).unwrap(), 0); // Test empty case
}