mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2025-09-09 07:38:50 +00:00
Format codebase with rustfmt
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user