guidelumineux@fairytail01:~$ cd "$HOME/Bibliotheca-Test/bibliotheca-app" echo "===== 1. Vérification du fichier =====" ls -lh src-tauri/src/lib.rs echo echo "===== 2. Empreinte SHA256 avant correction =====" sha256sum src-tauri/src/lib.rs echo echo "===== 3. Vérification du formatage actuel =====" rustfmt --edition 2021 --check src-tauri/src/lib.rs ===== 1. Vérification du fichier ===== -rw------- 1 guidelumineux guidelumineux 467K déc. 3 16:53 src-tauri/src/lib.rs ===== 2. Empreinte SHA256 avant correction ===== b03fc13e012b1a4110199e0a7eb341030994c175ee9edaeca915fce4a63113af src-tauri/src/lib.rs ===== 3. Vérification du formatage actuel ===== Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1: -use rusqlite::{params_from_iter, Connection, OptionalExtension, params}; use rusqlite::types::Value; -use std::collections::{HashMap, HashSet}; +use rusqlite::{params, params_from_iter, Connection, OptionalExtension}; use serde::{Deserialize, Serialize}; +use std::collections::{HashMap, HashSet}; +use std::io::Read; use std::path::{Path, PathBuf}; use std::sync::Mutex; -use std::io::Read; use tauri::{ipc::Response, Manager, State}; use uuid::Uuid; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:22: path: PathBuf, } - struct FileAssociationsState { path: PathBuf, downloads_path: PathBuf, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:29: lock: Mutex<()>, } - #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct StorageRootEntry { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:60: roots: Vec, } - fn ensure_storage_directory(path: &Path) -> Result<(), String> { let absolute = if path.is_absolute() { path.to_path_buf() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:178: true } -fn validate_storage_roots_document( - document: &StorageRootsDocument, -) -> Result<(), String> { +fn validate_storage_roots_document(document: &StorageRootsDocument) -> Result<(), String> { if document.version != 1 { return Err(format!( "Version de configuration des racines non prise en charge : {}", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:189: } if document.roots.is_empty() { - return Err( - "La configuration ne contient aucune racine de stockage.".into() - ); + return Err("La configuration ne contient aucune racine de stockage.".into()); } let mut ids = HashSet::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:198: let mut has_managed_root = false; for root in &document.roots { - if root.id.trim().is_empty() - || root.label.trim().is_empty() - || root.path.trim().is_empty() + if root.id.trim().is_empty() || root.label.trim().is_empty() || root.path.trim().is_empty() { return Err( - "Une racine de stockage possède un identifiant, un nom ou un chemin vide." - .into() + "Une racine de stockage possède un identifiant, un nom ou un chemin vide.".into(), ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:211: let parsed_id = Uuid::parse_str(&root.id).map_err(|_| { - format!("Identifiant de racine qui n'est pas un UUID valide : {}", root.id) + format!( + "Identifiant de racine qui n'est pas un UUID valide : {}", + root.id + ) })?; if parsed_id.get_version_num() != 4 { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:233: has_managed_root = true; if path.is_absolute() - || !path.components().all(|component| { - matches!(component, std::path::Component::Normal(_)) - }) + || !path + .components() + .all(|component| matches!(component, std::path::Component::Normal(_))) { return Err(format!( "Le chemin de la racine gérée doit être relatif et sans traversée de dossier : {}", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:252: } } other => { - return Err(format!( - "Type de racine de stockage inconnu : {other}" - )); + return Err(format!("Type de racine de stockage inconnu : {other}")); } } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:261: if !has_managed_root { - return Err( - "La configuration doit conserver au moins une racine gérée.".into() - ); + return Err("La configuration doit conserver au moins une racine gérée.".into()); } Ok(()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:302: format!("Écriture de la configuration des racines impossible : {error}") })?; - file.sync_all().map_err(|error| { - format!("Synchronisation de la configuration impossible : {error}") - })?; + file.sync_all() + .map_err(|error| format!("Synchronisation de la configuration impossible : {error}"))?; Ok(()) })(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:317: result } -fn initialize_storage_roots( - test_root: &Path, -) -> Result { +fn initialize_storage_roots(test_root: &Path) -> Result { let configuration_dir = test_root.join("configuration"); ensure_storage_directory(&configuration_dir)?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:328: match std::fs::symlink_metadata(&config_path) { Ok(metadata) => { if metadata.file_type().is_symlink() || !metadata.is_file() { - return Err( - "Le fichier storage-roots.json n'est pas un fichier ordinaire." - .into() - ); + return Err("Le fichier storage-roots.json n'est pas un fichier ordinaire.".into()); } } Err(error) if error.kind() == std::io::ErrorKind::NotFound => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:345: } let content = std::fs::read_to_string(&config_path) - .map_err(|error| { - format!("Lecture de storage-roots.json impossible : {error}") - })?; + .map_err(|error| format!("Lecture de storage-roots.json impossible : {error}"))?; - let document: StorageRootsDocument = - serde_json::from_str(&content).map_err(|error| { - format!("Configuration des racines invalide : {error}") - })?; + let document: StorageRootsDocument = serde_json::from_str(&content) + .map_err(|error| format!("Configuration des racines invalide : {error}"))?; validate_storage_roots_document(&document)?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:364: let path = test_root.join(&root.path); ensure_storage_directory(&path)?; - for directory in [ - "lectures", - "illustrations", - "documents", - "couvertures", - ] { + for directory in ["lectures", "illustrations", "documents", "couvertures"] { ensure_storage_directory(&path.join(directory))?; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:461: let valid_key = !key.is_empty() && key.as_bytes()[0].is_ascii_lowercase() && key.bytes().all(|byte| { - byte.is_ascii_lowercase() - || byte.is_ascii_digit() - || byte == b'_' - || byte == b'-' + byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'_' || byte == b'-' }); if !valid_key { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:501: if !keys.contains(inverse) { return Err(format!( "Le type '{}' référence le type inverse '{}', absent du catalogue.", - relation_type.key, - inverse + relation_type.key, inverse )); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:538: } } -fn allocate_file_association_id( - document: &mut FileAssociationsDocument, -) -> Result { +fn allocate_file_association_id(document: &mut FileAssociationsDocument) -> Result { // Compatibilité avec les anciens JSON qui ne possèdent pas next_id. - let highest_existing_id = document.associations + let highest_existing_id = document + .associations .iter() .map(|association| association.id) .max() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:550: let base = document.next_id.max(highest_existing_id); - let next = base.checked_add(1) + let next = base + .checked_add(1) .ok_or_else(|| "Impossible de générer un nouvel identifiant.".to_string())?; document.next_id = next; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:578: Ok(document) } -fn write_file_associations( - path: &Path, - document: &FileAssociationsDocument, -) -> Result<(), String> { - let parent = path.parent() +fn write_file_associations(path: &Path, document: &FileAssociationsDocument) -> Result<(), String> { + let parent = path + .parent() .ok_or_else(|| "Dossier du fichier d'associations introuvable.".to_string())?; std::fs::create_dir_all(parent) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:604: Ok(()) } - #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] struct WorkFileLimitStatus { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:615: customized: bool, } -fn default_work_file_limit( - connection: &Connection, - form_key: &str, -) -> Result { +fn default_work_file_limit(connection: &Connection, form_key: &str) -> Result { let limit: i64 = connection.query_row( "SELECT default_limit FROM work_file_limits Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:638: usize::try_from(limit) .ok() .filter(|value| *value > 0) - .ok_or_else(|| { - format!("La limite de fichiers définie pour '{form_key}' est invalide.") - }) + .ok_or_else(|| format!("La limite de fichiers définie pour '{form_key}' est invalide.")) } -fn custom_work_file_limit( - connection: &Connection, - work_id: i64, -) -> Result, String> { - let custom_limit: Option = connection.query_row( - "SELECT custom_limit +fn custom_work_file_limit(connection: &Connection, work_id: i64) -> Result, String> { + let custom_limit: Option = connection + .query_row( + "SELECT custom_limit FROM work_file_limit_overrides WHERE work_id = ?1", - [work_id], - |row| row.get(0), - ).optional() - .map_err(|error| { - format!("Lecture de la limite personnalisée impossible : {error}") - })?; + [work_id], + |row| row.get(0), + ) + .optional() + .map_err(|error| format!("Lecture de la limite personnalisée impossible : {error}"))?; - custom_limit.map(|limit| { - usize::try_from(limit) - .ok() - .filter(|value| *value > 0) - .ok_or_else(|| { - format!("La limite personnalisée de l'œuvre {work_id} est invalide.") - }) - }).transpose() + custom_limit + .map(|limit| { + usize::try_from(limit) + .ok() + .filter(|value| *value > 0) + .ok_or_else(|| { + format!("La limite personnalisée de l'œuvre {work_id} est invalide.") + }) + }) + .transpose() } fn make_work_file_limit_status( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:675: associations: &FileAssociationsDocument, ) -> Result { let default_limit = default_work_file_limit(connection, form_key)?; - let current_count = associations.associations.iter() + let current_count = associations + .associations + .iter() .filter(|association| association.work_id == work_id) .count(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:735: database: State<'_, Database>, associations: State<'_, FileAssociationsState>, ) -> Result { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:742: - let form: String = connection.query_row( - "SELECT editorial_form FROM works WHERE id = ?1", - [work_id], - |row| row.get(0), - ).map_err(|error| { - if matches!(error, rusqlite::Error::QueryReturnedNoRows) { - "Cette œuvre n'existe pas.".to_string() - } else { - error.to_string() - } - })?; + let form: String = connection + .query_row( + "SELECT editorial_form FROM works WHERE id = ?1", + [work_id], + |row| row.get(0), + ) + .map_err(|error| { + if matches!(error, rusqlite::Error::QueryReturnedNoRows) { + "Cette œuvre n'existe pas.".to_string() + } else { + error.to_string() + } + })?; - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:758: let association_document = read_file_associations(&associations.path)?; - make_work_file_limit_status( - &connection, - &form, - work_id, - &association_document, - ) + make_work_file_limit_status(&connection, &form, work_id, &association_document) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:772: database: State<'_, Database>, associations: State<'_, FileAssociationsState>, ) -> Result { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:779: - let form: String = connection.query_row( - "SELECT editorial_form FROM works WHERE id = ?1", - [work_id], - |row| row.get(0), - ).map_err(|error| { - if matches!(error, rusqlite::Error::QueryReturnedNoRows) { - "Cette œuvre n'existe pas.".to_string() - } else { - error.to_string() - } - })?; + let form: String = connection + .query_row( + "SELECT editorial_form FROM works WHERE id = ?1", + [work_id], + |row| row.get(0), + ) + .map_err(|error| { + if matches!(error, rusqlite::Error::QueryReturnedNoRows) { + "Cette œuvre n'existe pas.".to_string() + } else { + error.to_string() + } + })?; let default_limit = default_work_file_limit(&connection, &form)?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:793: - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:797: let association_document = read_file_associations(&associations.path)?; - let current_count = association_document.associations.iter() + let current_count = association_document + .associations + .iter() .filter(|association| association.work_id == work_id) .count(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:803: - validate_new_work_file_limit( - default_limit, - current_count, - new_limit, - )?; + validate_new_work_file_limit(default_limit, current_count, new_limit)?; if new_limit == default_limit { - connection.execute( - "DELETE FROM work_file_limit_overrides WHERE work_id = ?1", - [work_id], - ).map_err(|error| { - format!("Suppression de la limite personnalisée impossible : {error}") - })?; + connection + .execute( + "DELETE FROM work_file_limit_overrides WHERE work_id = ?1", + [work_id], + ) + .map_err(|error| { + format!("Suppression de la limite personnalisée impossible : {error}") + })?; } else { let new_limit_sql = i64::try_from(new_limit) .map_err(|_| "La limite demandée est trop élevée pour SQLite.".to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:819: - connection.execute( - "INSERT INTO work_file_limit_overrides (work_id, custom_limit) + connection + .execute( + "INSERT INTO work_file_limit_overrides (work_id, custom_limit) VALUES (?1, ?2) ON CONFLICT(work_id) DO UPDATE SET custom_limit = excluded.custom_limit", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:825: - rusqlite::params![work_id, new_limit_sql], - ).map_err(|error| { - format!("Enregistrement de la limite personnalisée impossible : {error}") - })?; + rusqlite::params![work_id, new_limit_sql], + ) + .map_err(|error| { + format!("Enregistrement de la limite personnalisée impossible : {error}") + })?; } - make_work_file_limit_status( - &connection, - &form, - work_id, - &association_document, - ) + make_work_file_limit_status(&connection, &form, work_id, &association_document) } -fn copy_file_without_overwriting( - source: &Path, - destination_dir: &Path, -) -> Result { +fn copy_file_without_overwriting(source: &Path, destination_dir: &Path) -> Result { if !source.is_file() { return Err("Le fichier source n'existe plus ou n'est pas un fichier ordinaire.".into()); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:852: .and_then(|name| name.to_str()) .ok_or_else(|| "Nom de fichier source invalide.".to_string())?; - let stem = source.file_stem() + let stem = source + .file_stem() .and_then(|name| name.to_str()) .ok_or_else(|| "Nom de fichier source invalide.".to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:878: { Ok(file) => file, Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => { - index = index.checked_add(1) + index = index + .checked_add(1) .ok_or_else(|| "Trop de fichiers portant ce nom.".to_string())?; continue; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:913: database: State<'_, Database>, associations: State<'_, FileAssociationsState>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:920: - let exists: bool = connection.query_row( - "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", - [work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + let exists: bool = connection + .query_row( + "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", + [work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !exists { return Err("Cette œuvre n'existe pas.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:928: } - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:934: let document = read_file_associations(&associations.path)?; - Ok(document.associations.iter() - .filter(|association| { - association.work_id == work_id && association.unit_id.is_none() - }) + Ok(document + .associations + .iter() + .filter(|association| association.work_id == work_id && association.unit_id.is_none()) .map(|association| WorkFile { id: association.id, original_filename: Path::new(&association.file) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:952: fn list_reader_file_availability( associations: State<'_, FileAssociationsState>, ) -> Result, String> { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:980: Ok(_) => (true, "accessible"), Err(_) => (false, "inaccessible"), }, - Err(error) if error.kind() == std::io::ErrorKind::NotFound => { - (false, "missing") - } + Err(error) if error.kind() == std::io::ErrorKind::NotFound => (false, "missing"), Err(_) => (false, "inaccessible"), }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1000: Ok(result) } - const READER_MAX_IMAGE_BYTES: u64 = 64 * 1024 * 1024; const READER_MAX_ARCHIVE_ENTRIES: usize = 100_000; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1018: associations: &FileAssociationsState, association_id: i64, ) -> Result { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1025: let document = read_file_associations(&associations.path)?; - let association = document.associations + let association = document + .associations .iter() .find(|item| item.id == association_id) .ok_or_else(|| "Association de fichier introuvable.".to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1033: } fn reader_image_extension(name: &str) -> Option { - let extension = Path::new(name) - .extension()? - .to_str()? - .to_ascii_lowercase(); + let extension = Path::new(name).extension()?.to_str()?.to_ascii_lowercase(); if matches!(extension.as_str(), "jpg" | "jpeg" | "png" | "webp") { Some(extension) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1051: ) -> Result { let path = reader_association_path(associations, association_id)?; - let extension = path.extension() + let extension = path + .extension() .and_then(|value| value.to_str()) .unwrap_or("") .to_ascii_lowercase(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1073: if reader_image_extension( path.file_name() .and_then(|name| name.to_str()) - .unwrap_or("") - ).is_none() { + .unwrap_or(""), + ) + .is_none() + { return Err("Format d'image non pris en charge.".into()); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1081: let file = std::fs::File::open(&path) .map_err(|error| format!("Ouverture du fichier impossible : {error}"))?; - let metadata = file.metadata() - .map_err(|error| error.to_string())?; + let metadata = file.metadata().map_err(|error| error.to_string())?; if !metadata.is_file() { return Err("L'association ne désigne pas un fichier ordinaire.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1095: let mut bytes = Vec::with_capacity(metadata.len() as usize); let mut limited = file.take(READER_MAX_IMAGE_BYTES + 1); - limited.read_to_end(&mut bytes) + limited + .read_to_end(&mut bytes) .map_err(|error| format!("Lecture de l'image impossible : {error}"))?; if bytes.len() as u64 > READER_MAX_IMAGE_BYTES { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1125: let mut result = Vec::new(); for entry_index in 0..archive.len() { - let entry = archive.by_index(entry_index) + let entry = archive + .by_index(entry_index) .map_err(|error| format!("Lecture de l'index ZIP impossible : {error}"))?; if !entry.is_file() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1132: continue; } - let name = entry.name() + let name = entry + .name() .map_err(|error| format!("Nom d'entrée ZIP invalide : {error}"))? .into_owned(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1172: return Err("Index de page hors limites.".into()); } - let entry = archive.by_index(entry_index) + let entry = archive + .by_index(entry_index) .map_err(|error| format!("Lecture de la page impossible : {error}"))?; if !entry.is_file() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1179: return Err("Cette entrée ZIP n'est pas un fichier.".into()); } - let name = entry.name() + let name = entry + .name() .map_err(|error| format!("Nom d'entrée ZIP invalide : {error}"))?; if reader_image_extension(name.as_ref()).is_none() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1193: let mut bytes = Vec::with_capacity(entry.size() as usize); let mut limited = entry.take(READER_MAX_IMAGE_BYTES + 1); - limited.read_to_end(&mut bytes) + limited + .read_to_end(&mut bytes) .map_err(|error| format!("Lecture de la page impossible : {error}"))?; if bytes.len() as u64 > READER_MAX_IMAGE_BYTES { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1212: "Une nouvelle association doit être rattachée au conteneur principal ou à une unité auxiliaire.".to_string() })?; - let belongs_to_work: bool = connection.query_row( - "SELECT EXISTS( + let belongs_to_work: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM work_units WHERE id = ?1 AND work_id = ?2 )", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1220: - rusqlite::params![unit_id, work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![unit_id, work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !belongs_to_work { return Err("Cette unité n'appartient pas à cette œuvre.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1226: } - let is_retired: bool = connection.query_row( - "SELECT is_retired FROM work_units + let is_retired: bool = connection + .query_row( + "SELECT is_retired FROM work_units WHERE id = ?1 AND work_id = ?2", - rusqlite::params![unit_id, work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![unit_id, work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if is_retired { return Err( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1237: - "Cette unité est retirée et ne peut plus recevoir de nouveaux fichiers." - .into() + "Cette unité est retirée et ne peut plus recevoir de nouveaux fichiers.".into(), ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1254: return Ok(Vec::new()); } - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1261: - let exists: bool = connection.query_row( - "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", - [work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + let exists: bool = connection + .query_row( + "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", + [work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !exists { return Err("Cette œuvre n'existe pas.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1269: } - let unit_id = validate_file_association_unit( - &connection, - work_id, - unit_id, - )?; + let unit_id = validate_file_association_unit(&connection, work_id, unit_id)?; let mut validated_paths = Vec::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1292: validated_paths.push(file_path); } - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1311: // Le quota porte sur toutes les associations de l'œuvre, // qu'elles soient directes ou rattachées à une unité. - let current_count = document.associations.iter() + let current_count = document + .associations + .iter() .filter(|association| association.work_id == work_id) .count(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1318: - let requested_count = current_count.checked_add(validated_paths.len()) + let requested_count = current_count + .checked_add(validated_paths.len()) .ok_or_else(|| "Nombre d'associations trop élevé.".to_string())?; - let form: String = connection.query_row( - "SELECT editorial_form FROM works WHERE id = ?1", - [work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + let form: String = connection + .query_row( + "SELECT editorial_form FROM works WHERE id = ?1", + [work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; let default_limit = default_work_file_limit(&connection, &form)?; - let active_limit = custom_work_file_limit(&connection, work_id)? - .unwrap_or(default_limit); + let active_limit = custom_work_file_limit(&connection, work_id)?.unwrap_or(default_limit); - validate_work_file_limit( - current_count, - requested_count, - active_limit, - )?; + validate_work_file_limit(current_count, requested_count, active_limit)?; let mut added_ids = Vec::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1359: association_id: i64, associations: State<'_, FileAssociationsState>, ) -> Result<(), String> { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1366: let mut document = read_file_associations(&associations.path)?; let previous_len = document.associations.len(); - document.associations.retain(|association| { - association.id != association_id - }); + document + .associations + .retain(|association| association.id != association_id); if document.associations.len() == previous_len { return Err("Association introuvable.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1377: write_file_associations(&associations.path, &document) } - #[tauri::command] fn remove_all_file_associations( work_id: i64, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1384: database: State<'_, Database>, associations: State<'_, FileAssociationsState>, ) -> Result { - remove_all_file_associations_internal( - work_id, - &database, - &associations, - ) + remove_all_file_associations_internal(work_id, &database, &associations) } fn remove_all_file_associations_internal( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1397: associations: &FileAssociationsState, ) -> Result { { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1404: - let exists: bool = connection.query_row( - "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", - [work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + let exists: bool = connection + .query_row( + "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", + [work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !exists { return Err("Cette œuvre n'existe pas.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1412: } } - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1419: let mut document = read_file_associations(&associations.path)?; let previous_len = document.associations.len(); - document.associations.retain(|association| { - association.work_id != work_id - }); + document + .associations + .retain(|association| association.work_id != work_id); let removed = previous_len - document.associations.len(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1438: associations: State<'_, FileAssociationsState>, ) -> Result { let source_path = { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1445: let document = read_file_associations(&associations.path)?; - document.associations.iter() + document + .associations + .iter() .find(|association| association.id == association_id) .map(|association| PathBuf::from(&association.file)) .ok_or_else(|| "Association introuvable.".to_string())? Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1455: copy_file_without_overwriting(&source_path, &downloads) } - - #[derive(Serialize)] #[serde(rename_all = "camelCase")] struct BulkDownloadReport { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1477: for character in value.chars() { if character.is_control() - || matches!(character, '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|') + || matches!( + character, + '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' + ) { cleaned.push('-'); } else { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1497: let is_reserved = matches!( reserved.as_str(), - "CON" | "PRN" | "AUX" | "NUL" - | "COM1" | "COM2" | "COM3" | "COM4" | "COM5" - | "COM6" | "COM7" | "COM8" | "COM9" - | "LPT1" | "LPT2" | "LPT3" | "LPT4" | "LPT5" - | "LPT6" | "LPT7" | "LPT8" | "LPT9" + "CON" + | "PRN" + | "AUX" + | "NUL" + | "COM1" + | "COM2" + | "COM3" + | "COM4" + | "COM5" + | "COM6" + | "COM7" + | "COM8" + | "COM9" + | "LPT1" + | "LPT2" + | "LPT3" + | "LPT4" + | "LPT5" + | "LPT6" + | "LPT7" + | "LPT8" + | "LPT9" ); if cleaned.is_empty() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1581: let destination = PathBuf::from(destination_dir); std::fs::create_dir_all(&destination) - .map_err(|error| { - format!("Création du dossier de destination impossible : {error}") - })?; + .map_err(|error| format!("Création du dossier de destination impossible : {error}"))?; if !destination.is_dir() { return Err("La destination choisie n'est pas un dossier.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1592: // Lecture du JSON sous son verrou habituel. // Aucun changement n'est apporté aux associations. let document = { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1609: // Validation SQL et résolution du propriétaire réel de chaque unité. { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1636: return Err(format!("Œuvre sélectionnée introuvable : {work_id}")); } - let main_unit_id: i64 = connection.query_row( - "SELECT id + let main_unit_id: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1644: - params![work_id], - |row| row.get(0), - ).map_err(|_| { - format!( - "Conteneur principal introuvable pour l'œuvre {work_id}." + params![work_id], + |row| row.get(0), ) - })?; + .map_err(|_| format!("Conteneur principal introuvable pour l'œuvre {work_id}."))?; main_unit_ids.insert(*work_id, main_unit_id); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1659: |row| row.get(0), ); - let owner = owner.map_err(|_| { - format!("Unité sélectionnée introuvable : {unit_id}") - })?; + let owner = owner.map_err(|_| format!("Unité sélectionnée introuvable : {unit_id}"))?; selected_unit_owners.insert(*unit_id, owner); effective_work_ids.insert(owner); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1673: // Une unité explicitement sélectionnée sélectionne ses propres fichiers. for association in &document.associations { let selected_by_work = selected_work_ids.contains(&association.work_id) - && association.unit_id == main_unit_ids - .get(&association.work_id) - .copied(); + && association.unit_id == main_unit_ids.get(&association.work_id).copied(); - let selected_by_unit = association.unit_id + let selected_by_unit = association + .unit_id .map(|id| selected_unit_ids.contains(&id)) .unwrap_or(false); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1686: } if let Some(unit_id) = association.unit_id { - let actual_owner = if let Some(owner) = - selected_unit_owners.get(&unit_id) - { + let actual_owner = if let Some(owner) = selected_unit_owners.get(&unit_id) { *owner } else { - connection.query_row( - "SELECT work_id FROM work_units WHERE id = ?1", - params![unit_id], - |row| row.get::<_, i64>(0), - ).map_err(|_| { - format!( - "Association incohérente : l'unité {unit_id} n'existe plus." + connection + .query_row( + "SELECT work_id FROM work_units WHERE id = ?1", + params![unit_id], + |row| row.get::<_, i64>(0), ) - })? + .map_err(|_| { + format!("Association incohérente : l'unité {unit_id} n'existe plus.") + })? }; if actual_owner != association.work_id { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1706: return Err(format!( "Association incohérente : le fichier associé à l'œuvre {} \ référence une unité appartenant à l'œuvre {}.", - association.work_id, - actual_owner + association.work_id, actual_owner )); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1722: let mut work_infos = HashMap::::new(); { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1729: for work_id in &effective_work_ids { - let info = connection.query_row( - "SELECT COALESCE(NULLIF(title_english, ''), title_original), + let info = connection + .query_row( + "SELECT COALESCE(NULLIF(title_english, ''), title_original), editorial_form, editorial_subform FROM works Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1735: WHERE id = ?1", - params![work_id], - |row| { - Ok(WorkDownloadInfo { - title: row.get(0)?, - form: row.get(1)?, - subform: row.get(2)?, - }) - }, - ).map_err(|_| { - format!("Œuvre propriétaire introuvable : {work_id}") - })?; + params![work_id], + |row| { + Ok(WorkDownloadInfo { + title: row.get(0)?, + form: row.get(1)?, + subform: row.get(2)?, + }) + }, + ) + .map_err(|_| format!("Œuvre propriétaire introuvable : {work_id}"))?; work_infos.insert(*work_id, info); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1754: let (download_root, batch_name) = if global_batch { let requested_name = batch_folder_name .as_deref() - .ok_or_else(|| { - "Nom du dossier global manquant.".to_string() - })?; + .ok_or_else(|| "Nom du dossier global manquant.".to_string())?; - let (path, name) = - create_unique_batch_directory(&destination, requested_name)?; + let (path, name) = create_unique_batch_directory(&destination, requested_name)?; (path, Some(name)) } else { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1772: let mut base_names = HashMap::::new(); { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1779: - let mut statement = connection.prepare( - "SELECT COALESCE(NULLIF(title_english, ''), title_original), + let mut statement = connection + .prepare( + "SELECT COALESCE(NULLIF(title_english, ''), title_original), editorial_form, editorial_subform - FROM works" - ).map_err(|error| error.to_string())?; + FROM works", + ) + .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - let title: String = row.get(0)?; - let form: String = row.get(1)?; - let subform: Option = row.get(2)?; - Ok((title, form, subform)) - }).map_err(|error| error.to_string())?; + let rows = statement + .query_map([], |row| { + let title: String = row.get(0)?; + let form: String = row.get(1)?; + let subform: Option = row.get(2)?; + Ok((title, form, subform)) + }) + .map_err(|error| error.to_string())?; for row in rows { let (title, form, subform) = row.map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1795: let base = sanitize_folder_component(&format!( "{} - {}", title, - editorial_form_display_with_subform(&connection, &form, subform.as_deref()).map_err(|error| error.to_string())? + editorial_form_display_with_subform(&connection, &form, subform.as_deref()) + .map_err(|error| error.to_string())? )); *name_counts.entry(base).or_insert(0) += 1; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1802: for (work_id, info) in &work_infos { - let base = sanitize_folder_component( - &format!( - "{} - {}", - info.title, - editorial_form_display_with_subform( - &connection, - &info.form, - info.subform.as_deref() - ).map_err(|error| error.to_string())? + let base = sanitize_folder_component(&format!( + "{} - {}", + info.title, + editorial_form_display_with_subform( + &connection, + &info.form, + info.subform.as_deref() ) - ); + .map_err(|error| error.to_string())? + )); base_names.insert(*work_id, base); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1819: let mut work_directories = HashMap::::new(); let mut output_folders = Vec::::new(); - let mut ordered_work_ids: Vec = - effective_work_ids.iter().copied().collect(); + let mut ordered_work_ids: Vec = effective_work_ids.iter().copied().collect(); ordered_work_ids.sort_unstable(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1827: for work_id in &ordered_work_ids { - let base = base_names.get(work_id) - .ok_or_else(|| { - format!("Informations de l'œuvre {work_id} manquantes.") - })?; + let base = base_names + .get(work_id) + .ok_or_else(|| format!("Informations de l'œuvre {work_id} manquantes."))?; let folder_name = if name_counts.get(base).copied().unwrap_or(0) > 1 { format!("{base} [{work_id}]") Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1840: // Un dossier existant est réutilisé ; aucun fichier existant // ne sera écrasé par la fonction de copie. - std::fs::create_dir_all(&work_directory) - .map_err(|error| { - format!( - "Création du dossier de l'œuvre {work_id} impossible : {error}" - ) - })?; + std::fs::create_dir_all(&work_directory).map_err(|error| { + format!("Création du dossier de l'œuvre {work_id} impossible : {error}") + })?; if !work_directory.is_dir() { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1868: let source = PathBuf::from(&association.file); if !source.is_file() { - let name = source.file_name() + let name = source + .file_name() .and_then(|value| value.to_str()) .unwrap_or(&association.file) .to_string(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1882: Err(error) => { errors.push(format!( "{} : {error}", - source.file_name() + source + .file_name() .and_then(|value| value.to_str()) .unwrap_or("Fichier") )); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1890: } }; - let work_seen = seen.entry(association.work_id) - .or_insert_with(HashSet::new); + let work_seen = seen.entry(association.work_id).or_insert_with(HashSet::new); if !work_seen.insert(canonical.clone()) { continue; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1898: } - let work_directory = work_directories - .get(&association.work_id) - .ok_or_else(|| { - format!( - "Dossier de destination manquant pour l'œuvre {}.", - association.work_id - ) - })?; + let work_directory = work_directories.get(&association.work_id).ok_or_else(|| { + format!( + "Dossier de destination manquant pour l'œuvre {}.", + association.work_id + ) + })?; - match copy_file_without_overwriting( - &canonical, - work_directory, - ) { + match copy_file_without_overwriting(&canonical, work_directory) { Ok(_) => copied_files += 1, Err(error) => { - let name = canonical.file_name() + let name = canonical + .file_name() .and_then(|value| value.to_str()) .unwrap_or("Fichier"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1933: }) } - #[tauri::command] fn download_selected_associated_files( work_id: i64, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1962: return Err("Aucun fichier n'est sélectionné.".into()); } - let selected_ids: HashSet = - association_ids.iter().copied().collect(); + let selected_ids: HashSet = association_ids.iter().copied().collect(); if selected_ids.len() != association_ids.len() { return Err("La sélection contient des identifiants en double.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1971: // Lire les associations sous le verrou, sans modifier le JSON. let document = { - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1978: read_file_associations(&associations.path)? }; - let selected_associations: Vec = - document.associations.iter() - .filter(|association| selected_ids.contains(&association.id)) - .cloned() - .collect(); + let selected_associations: Vec = document + .associations + .iter() + .filter(|association| selected_ids.contains(&association.id)) + .cloned() + .collect(); if selected_associations.len() != selected_ids.len() { return Err("Une ou plusieurs associations sélectionnées n'existent plus.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1989: } - if selected_associations.iter().any(|association| { - association.work_id != work_id - }) { + if selected_associations + .iter() + .any(|association| association.work_id != work_id) + { return Err("Une association sélectionnée n'appartient pas à cette œuvre.".into()); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:1997: // Vérifier l'œuvre et la propriété réelle de chaque unité. let (work_info, folder_name) = { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2003: - let info = connection.query_row( - "SELECT COALESCE(NULLIF(title_english, ''), title_original), + let info = connection + .query_row( + "SELECT COALESCE(NULLIF(title_english, ''), title_original), editorial_form, editorial_subform FROM works Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2008: WHERE id = ?1", - [work_id], - |row| { - Ok(WorkDownloadInfo { - title: row.get(0)?, - form: row.get(1)?, - subform: row.get(2)?, - }) - }, - ).map_err(|_| { - format!("Œuvre sélectionnée introuvable : {work_id}") - })?; + [work_id], + |row| { + Ok(WorkDownloadInfo { + title: row.get(0)?, + form: row.get(1)?, + subform: row.get(2)?, + }) + }, + ) + .map_err(|_| format!("Œuvre sélectionnée introuvable : {work_id}"))?; for association in &selected_associations { if let Some(unit_id) = association.unit_id { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2023: - let owner: i64 = connection.query_row( - "SELECT work_id FROM work_units WHERE id = ?1", - [unit_id], - |row| row.get(0), - ).map_err(|_| { - format!("L'unité {unit_id} associée n'existe plus.") - })?; + let owner: i64 = connection + .query_row( + "SELECT work_id FROM work_units WHERE id = ?1", + [unit_id], + |row| row.get(0), + ) + .map_err(|_| format!("L'unité {unit_id} associée n'existe plus."))?; if owner != work_id { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2036: } } - let base = sanitize_folder_component( - &format!( - "{} - {}", - info.title, - editorial_form_display_with_subform( - &connection, - &info.form, - info.subform.as_deref() - ).map_err(|error| error.to_string())? - ) - ); + let base = sanitize_folder_component(&format!( + "{} - {}", + info.title, + editorial_form_display_with_subform(&connection, &info.form, info.subform.as_deref()) + .map_err(|error| error.to_string())? + )); - let mut statement = connection.prepare( - "SELECT COALESCE(NULLIF(title_english, ''), title_original), + let mut statement = connection + .prepare( + "SELECT COALESCE(NULLIF(title_english, ''), title_original), editorial_form, editorial_subform - FROM works" - ).map_err(|error| error.to_string())?; + FROM works", + ) + .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - let title: String = row.get(0)?; - let form: String = row.get(1)?; - let subform: Option = row.get(2)?; - Ok((title, form, subform)) - }).map_err(|error| error.to_string())?; + let rows = statement + .query_map([], |row| { + let title: String = row.get(0)?; + let form: String = row.get(1)?; + let subform: Option = row.get(2)?; + Ok((title, form, subform)) + }) + .map_err(|error| error.to_string())?; let mut same_name_count = 0usize; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2067: for row in rows { let (title, form, subform) = row.map_err(|error| error.to_string())?; - let candidate = - sanitize_folder_component(&format!( + let candidate = sanitize_folder_component(&format!( "{} - {}", title, - editorial_form_display_with_subform(&connection, &form, subform.as_deref()).map_err(|error| error.to_string())? + editorial_form_display_with_subform(&connection, &form, subform.as_deref()) + .map_err(|error| error.to_string())? )); if candidate == base { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2094: let destination = PathBuf::from(destination_dir); std::fs::create_dir_all(&destination) - .map_err(|error| { - format!("Création du dossier de destination impossible : {error}") - })?; + .map_err(|error| format!("Création du dossier de destination impossible : {error}"))?; if !destination.is_dir() { return Err("La destination choisie n'est pas un dossier.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2105: let work_directory = destination.join(&folder_name); std::fs::create_dir_all(&work_directory) - .map_err(|error| { - format!("Création du dossier de l'œuvre impossible : {error}") - })?; + .map_err(|error| format!("Création du dossier de l'œuvre impossible : {error}"))?; if !work_directory.is_dir() { return Err("Le chemin de destination de l'œuvre n'est pas un dossier.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2122: let source = PathBuf::from(&association.file); if !source.is_file() { - let name = source.file_name() + let name = source + .file_name() .and_then(|value| value.to_str()) .unwrap_or(&association.file) .to_string(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2136: Err(error) => { errors.push(format!( "{} : {error}", - source.file_name() + source + .file_name() .and_then(|value| value.to_str()) .unwrap_or("Fichier") )); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2148: continue; } - match copy_file_without_overwriting( - &canonical, - &work_directory, - ) { + match copy_file_without_overwriting(&canonical, &work_directory) { Ok(_) => copied_files += 1, Err(error) => { - let name = canonical.file_name() + let name = canonical + .file_name() .and_then(|value| value.to_str()) .unwrap_or("Fichier"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2344: form: Option, subform: Option, ) -> rusqlite::Result> { - form.map(|value| { - editorial_form_display_with_subform( - connection, - &value, - subform.as_deref(), - ) - }) - .transpose() + form.map(|value| editorial_form_display_with_subform(connection, &value, subform.as_deref())) + .transpose() } fn load_work_adaptations( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2427: AND wa.direction = 'from' AND ?2 = 'into' ) - ORDER BY related_title COLLATE NOCASE" + ORDER BY related_title COLLATE NOCASE", )?; - let rows = statement.query_map( - params![work_id, display_direction], - |row| { - let form: Option = row.get(3)?; - let subform: Option = row.get(4)?; + let rows = statement.query_map(params![work_id, display_direction], |row| { + let form: Option = row.get(3)?; + let subform: Option = row.get(4)?; - Ok(AdaptedWork { - id: row.get(0)?, - uuid: row.get(1)?, - title: row.get(2)?, - form: optional_editorial_form_display(connection, form, subform)?, - }) - }, - )?; + Ok(AdaptedWork { + id: row.get(0)?, + uuid: row.get(1)?, + title: row.get(2)?, + form: optional_editorial_form_display(connection, form, subform)?, + }) + })?; rows.collect() } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2479: FROM work_adaptations wa LEFT JOIN works owner ON owner.id = wa.related_work_id WHERE wa.work_id = ?1 - ORDER BY wa.related_work_title COLLATE NOCASE" + ORDER BY wa.related_work_title COLLATE NOCASE", )?; let rows = statement.query_map([work_id], |row| { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2529: WHERE wa.related_work_id = ?1 ORDER BY COALESCE(NULLIF(owner.title_english, ''), owner.title_original) - COLLATE NOCASE" + COLLATE NOCASE", )?; let rows = statement.query_map([work_id], |row| { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2586: #[tauri::command] fn database_status(database: State<'_, Database>) -> Result { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2617: fn list_advanced_search_families( database: State<'_, Database>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2624: - let mut statement = connection.prepare( - "SELECT family_key, label, value_kind + let mut statement = connection + .prepare( + "SELECT family_key, label, value_kind FROM advanced_search_families WHERE is_available = 1 - ORDER BY sort_order, label COLLATE NOCASE" - ).map_err(|error| error.to_string())?; + ORDER BY sort_order, label COLLATE NOCASE", + ) + .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - Ok(AdvancedSearchFamily { - key: row.get(0)?, - label: row.get(1)?, - value_kind: row.get(2)?, + let rows = statement + .query_map([], |row| { + Ok(AdvancedSearchFamily { + key: row.get(0)?, + label: row.get(1)?, + value_kind: row.get(2)?, + }) }) - }).map_err(|error| error.to_string())?; + .map_err(|error| error.to_string())?; rows.collect::, _>>() .map_err(|error| error.to_string()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2646: value: &str, values: &mut Vec, ) -> Result { - let family_key: String = connection.query_row( - "SELECT family_key + let family_key: String = connection + .query_row( + "SELECT family_key FROM advanced_search_families WHERE label = ?1 COLLATE NOCASE AND is_available = 1", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2654: - [field], - |row| row.get(0), - ).optional().map_err(|error| error.to_string())? + [field], + |row| row.get(0), + ) + .optional() + .map_err(|error| error.to_string())? .ok_or_else(|| format!("Critère inconnu ou indisponible : « {} ».", field))?; - let exact = |expression: &str| { - format!( - "lower(trim(COALESCE(({expression}), ''))) = lower(trim(?))" - ) - }; + let exact = + |expression: &str| format!("lower(trim(COALESCE(({expression}), ''))) = lower(trim(?))"); let sql = match family_key.as_str() { "format" => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2681: WHERE ef.form_key = w.editorial_form), w.editorial_form ) - END" + END", ) } "subformat" => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2721: } "publisher_type" => { values.push(Value::Text(value.to_string())); - exact("(SELECT pt.label FROM publisher_types pt - WHERE pt.publisher_type_key = w.publisher_type)") + exact( + "(SELECT pt.label FROM publisher_types pt + WHERE pt.publisher_type_key = w.publisher_type)", + ) } "publisher_name" => { values.push(Value::Text(value.to_string())); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2730: } "status" => { values.push(Value::Text(value.to_string())); - exact("(SELECT ws.label FROM work_statuses ws - WHERE ws.status_key = w.status)") + exact( + "(SELECT ws.label FROM work_statuses ws + WHERE ws.status_key = w.status)", + ) } "genre" => { values.push(Value::Text(value.to_string())); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2780: } "original_language" => { values.push(Value::Text(value.to_string())); - exact("(SELECT ol.label FROM original_languages ol - WHERE ol.language_key = w.original_language)") + exact( + "(SELECT ol.label FROM original_languages ol + WHERE ol.language_key = w.original_language)", + ) } "translation_language" => { values.push(Value::Text(value.to_string())); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2808: let number = match normalized.as_str() { "oui" => 1, "non" => 0, - _ => return Err( - "Pour « Œuvre en un seul tome », utilise « Oui » ou « Non ».".to_string() - ), + _ => { + return Err( + "Pour « Œuvre en un seul tome », utilise « Oui » ou « Non ».".to_string(), + ) + } }; values.push(Value::Integer(number)); "w.is_one_shot = ?".to_string() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2830: ) )", exact("wa.relation_label_snapshot"), - exact("(SELECT rt.label FROM relation_types rt - WHERE rt.relation_key = wa.direction)") + exact( + "(SELECT rt.label FROM relation_types rt + WHERE rt.relation_key = wa.direction)" + ) ) } "unit_type" => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2866: exact("w.start_date") } "volume_count" => { - let number = value.trim().parse::() + let number = value + .trim() + .parse::() .map_err(|_| "Le nombre de volumes doit être un entier.".to_string())?; values.push(Value::Integer(number)); "w.volume_count = ?".to_string() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2873: } "chapter_count" => { - let number = value.trim().parse::() + let number = value + .trim() + .parse::() .map_err(|_| "Le nombre de chapitres doit être un entier.".to_string())?; values.push(Value::Integer(number)); "w.chapter_count = ?".to_string() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2879: } "page_count" => { - let number = value.trim().parse::() + let number = value + .trim() + .parse::() .map_err(|_| "Le nombre de pages doit être un entier.".to_string())?; values.push(Value::Integer(number)); "w.page_count = ?".to_string() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2885: } "episode_count" => { - let number = value.trim().parse::() + let number = value + .trim() + .parse::() .map_err(|_| "Le nombre d’épisodes doit être un entier.".to_string())?; values.push(Value::Integer(number)); "w.episode_count = ?".to_string() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2891: } - _ => return Err(format!( - "Le critère « {} » n’est pas encore pris en charge.", - field - )), + _ => { + return Err(format!( + "Le critère « {} » n’est pas encore pris en charge.", + field + )) + } }; Ok(sql) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2906: use advanced_search::Expression; match expression { - Expression::Condition(condition) => advanced_search_condition_sql( - connection, - &condition.field, - &condition.value, - values, - ), + Expression::Condition(condition) => { + advanced_search_condition_sql(connection, &condition.field, &condition.value, values) + } Expression::Not(inner) => Ok(format!( "(NOT {})", advanced_search_expression_sql(connection, inner, values)? Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2945: database: State<'_, Database>, ) -> Result, String> { let parsed = advanced_search::parse_expression(&expression)?; - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2963: COLLATE NOCASE" ); - let mut statement = connection.prepare(&sql) + let mut statement = connection + .prepare(&sql) .map_err(|error| error.to_string())?; - let rows = statement.query_map(params_from_iter(values.iter()), |row| { - row.get::<_, i64>(0) - }).map_err(|error| error.to_string())?; + let rows = statement + .query_map(params_from_iter(values.iter()), |row| row.get::<_, i64>(0)) + .map_err(|error| error.to_string())?; rows.collect::, _>>() .map_err(|error| error.to_string()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2974: } #[tauri::command] -fn list_works( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_works(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:2986: } // Wrapper conservé pour les tests historiques. -fn list_works_with_connection( - connection: &Connection, -) -> Result, String> { +fn list_works_with_connection(connection: &Connection) -> Result, String> { let relation_types = load_relation_types(connection)?; list_works_with_relation_types(connection, &relation_types) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3152: let mut statement = connection.prepare(sql).map_err(|e| e.to_string())?; - let rows = statement.query_map([], |row| { - let form_key: String = row.get(5)?; - let subform_key: Option = row.get(36)?; + let rows = statement + .query_map([], |row| { + let form_key: String = row.get(5)?; + let subform_key: Option = row.get(36)?; - Ok(WorkRecord { - id: row.get(0)?, - title: row.get(1)?, - original: row.get(2)?, - romanized: row.get(3)?, - french: row.get(4)?, - form: editorial_form_display_with_subform( - connection, - &form_key, - subform_key.as_deref(), - )?, - form_key, - subform_key, - author: row.get(6)?, - illustrator: row.get(7)?, - publisher_type: row.get(8)?, - publisher: row.get(9)?, - start_date: row.get(10)?, - volumes: row.get(11)?, - chapters: row.get(12)?, - pages: row.get(13)?, - source_work: row.get(14)?, - source_form: optional_editorial_form_display( - connection, - row.get(15)?, - row.get(39)?, - )?, - source_work_id: row.get(32)?, - status: row.get(16)?, - cover: row.get(17)?, - genres: split_values(row.get(18)?), - demographics: split_values(row.get(19)?), - personal_tags: split_values(row.get(20)?), - secondary_tags: split_values(row.get(37)?), - erotic_tags: split_values(row.get(38)?), - translations: Vec::new(), - links: split_values(row.get(25)?), - sources: split_values(row.get(26)?), - history: split_values(row.get(27)?), - animation_format: row.get(28)?, - episodes: row.get(29)?, - one_shot: row.get::<_, bool>(30)?, - relations: load_work_relations( - connection, - row.get(0)?, - relation_types, - )?, - adapted_from: load_work_adaptations(connection, row.get(0)?, "from")?, - adapted_into: load_work_adaptations(connection, row.get(0)?, "into")?, - original_language: row.get(34)?, - size_unit_count: row.get(35)?, + Ok(WorkRecord { + id: row.get(0)?, + title: row.get(1)?, + original: row.get(2)?, + romanized: row.get(3)?, + french: row.get(4)?, + form: editorial_form_display_with_subform( + connection, + &form_key, + subform_key.as_deref(), + )?, + form_key, + subform_key, + author: row.get(6)?, + illustrator: row.get(7)?, + publisher_type: row.get(8)?, + publisher: row.get(9)?, + start_date: row.get(10)?, + volumes: row.get(11)?, + chapters: row.get(12)?, + pages: row.get(13)?, + source_work: row.get(14)?, + source_form: optional_editorial_form_display( + connection, + row.get(15)?, + row.get(39)?, + )?, + source_work_id: row.get(32)?, + status: row.get(16)?, + cover: row.get(17)?, + genres: split_values(row.get(18)?), + demographics: split_values(row.get(19)?), + personal_tags: split_values(row.get(20)?), + secondary_tags: split_values(row.get(37)?), + erotic_tags: split_values(row.get(38)?), + translations: Vec::new(), + links: split_values(row.get(25)?), + sources: split_values(row.get(26)?), + history: split_values(row.get(27)?), + animation_format: row.get(28)?, + episodes: row.get(29)?, + one_shot: row.get::<_, bool>(30)?, + relations: load_work_relations(connection, row.get(0)?, relation_types)?, + adapted_from: load_work_adaptations(connection, row.get(0)?, "from")?, + adapted_into: load_work_adaptations(connection, row.get(0)?, "into")?, + original_language: row.get(34)?, + size_unit_count: row.get(35)?, + }) }) - }).map_err(|e| e.to_string())?; + .map_err(|e| e.to_string())?; - let mut works = rows.collect::, _>>() + let mut works = rows + .collect::, _>>() .map_err(|e| e.to_string())?; drop(statement); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3217: - let mut translations_by_work: HashMap> = - HashMap::new(); + let mut translations_by_work: HashMap> = HashMap::new(); { - let mut translation_statement = connection.prepare( - "SELECT + let mut translation_statement = connection + .prepare( + "SELECT t.work_id, t.translation_type, tt.label, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3229: FROM translations t LEFT JOIN translation_types tt ON tt.translation_type_key = t.translation_type - ORDER BY t.work_id, t.id" - ).map_err(|error| error.to_string())?; + ORDER BY t.work_id, t.id", + ) + .map_err(|error| error.to_string())?; - let translation_rows = translation_statement.query_map([], |row| { - Ok(( - row.get::<_, i64>(0)?, - WorkTranslation { - translation_type: row.get(1)?, - label: row.get(2)?, - language_code: row.get(3)?, - chapter_range: row.get(4)?, - }, - )) - }).map_err(|error| error.to_string())?; + let translation_rows = translation_statement + .query_map([], |row| { + Ok(( + row.get::<_, i64>(0)?, + WorkTranslation { + translation_type: row.get(1)?, + label: row.get(2)?, + language_code: row.get(3)?, + chapter_range: row.get(4)?, + }, + )) + }) + .map_err(|error| error.to_string())?; for translation_row in translation_rows { - let (work_id, translation) = - translation_row.map_err(|error| error.to_string())?; + let (work_id, translation) = translation_row.map_err(|error| error.to_string())?; translations_by_work .entry(work_id) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3256: } for work in &mut works { - work.translations = translations_by_work - .remove(&work.id) - .unwrap_or_default(); + work.translations = translations_by_work.remove(&work.id).unwrap_or_default(); } Ok(works) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3265: } - #[derive(Deserialize, Default)] #[serde(rename_all = "camelCase")] struct CreateWorkInput { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3345: "Manga X" => ("ero_manga", None), "Doujinshi X" => ("ero_doujinshi", None), "Anime X" => ("animation_x", None), - "Bande dessinée occidentale" => { - ("bande_dessinee", Some("bd_occidentale")) - } + "Bande dessinée occidentale" => ("bande_dessinee", Some("bd_occidentale")), "BD d'inspiration manga" | "BD d’inspiration manga" => { ("bande_dessinee", Some("bd_inspiration_manga")) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3372: if let (Some(legacy), Some(explicit)) = (legacy_subform, explicit_subform) { if legacy != explicit { return Err( - "La sous-forme fournie contredit le libellé de forme historique." - .to_string() + "La sous-forme fournie contredit le libellé de forme historique.".to_string(), ); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3380: - let subform = legacy_subform - .or(explicit_subform) - .map(str::to_string); + let subform = legacy_subform.or(explicit_subform).map(str::to_string); if let Some(subform_key) = subform.as_deref() { - let valid: bool = connection.query_row( - "SELECT EXISTS( + let valid: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM editorial_form_subforms efs JOIN editorial_subforms es Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3393: AND efs.subform_key = ?2 AND es.is_available = 1 )", - params![form_key, subform_key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + params![form_key, subform_key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !valid { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3411: fn clean_work_text(value: Option) -> Option { value.and_then(|text| { let text = text.trim().to_string(); - if text.is_empty() { None } else { Some(text) } + if text.is_empty() { + None + } else { + Some(text) + } }) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3451: } if let Some(sql) = insert_sql { - transaction.execute(sql, [name]) + transaction + .execute(sql, [name]) .map_err(|error| error.to_string())?; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3458: - let id: i64 = transaction.query_row( - select_sql, - [name], - |row| row.get(0), - ).map_err(|error| { - if table == "tags" { - format!("Le tag « {name} » n'existe pas ou n'est plus disponible.") - } else { - error.to_string() - } - })?; + let id: i64 = transaction + .query_row(select_sql, [name], |row| row.get(0)) + .map_err(|error| { + if table == "tags" { + format!("Le tag « {name} » n'existe pas ou n'est plus disponible.") + } else { + error.to_string() + } + })?; - transaction.execute(association_sql, params![work_id, id]) + transaction + .execute(association_sql, params![work_id, id]) .map_err(|error| error.to_string())?; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3475: } #[tauri::command] -fn create_work( - input: CreateWorkInput, - database: State<'_, Database>, -) -> Result { - let mut connection = database.connection +fn create_work(input: CreateWorkInput, database: State<'_, Database>) -> Result { + let mut connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3511: AND is_available = 1" ); - connection.query_row(&sql, [value.trim()], |row| row.get::<_, String>(0)) + connection + .query_row(&sql, [value.trim()], |row| row.get::<_, String>(0)) .optional() .map_err(|error| error.to_string())? .ok_or_else(|| { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3555: } if catalog == "erotic_tags" { - let allowed: bool = transaction.query_row( - "SELECT EXISTS( + let allowed: bool = transaction + .query_row( + "SELECT EXISTS( SELECT 1 FROM form_erotic_tags WHERE form_key = ?1 )", - [form_key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + [form_key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !allowed { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3571: } } - let tag_id: i64 = transaction.query_row( - select_sql, - [name], - |row| row.get(0), - ).map_err(|_| { - format!( - "Le {} « {} » n'existe pas ou n'est plus disponible.", - family_label, name - ) - })?; + let tag_id: i64 = transaction + .query_row(select_sql, [name], |row| row.get(0)) + .map_err(|_| { + format!( + "Le {} « {} » n'existe pas ou n'est plus disponible.", + family_label, name + ) + })?; - transaction.execute( - association_sql, - params![work_id, tag_id], - ).map_err(|error| error.to_string())?; + transaction + .execute(association_sql, params![work_id, tag_id]) + .map_err(|error| error.to_string())?; } Ok(()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3602: input.original = input.original.trim().to_string(); - let (form_key, editorial_subform) = normalize_editorial_form( - connection, - &input.form, - input.editorial_subform.as_deref(), - )?; + let (form_key, editorial_subform) = + normalize_editorial_form(connection, &input.form, input.editorial_subform.as_deref())?; - let one_shot_allowed: bool = connection.query_row( - "SELECT EXISTS( + let one_shot_allowed: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM form_one_shot_rules WHERE form_key = ?1 AND allowed = 1 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3616: )", - [&form_key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + [&form_key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if input.one_shot && !one_shot_allowed { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3632: ("Épisodes", input.episodes), ] { if value.is_some_and(|number| number < 0) { - return Err(format!("Le nombre de {name_lower} ne peut pas être négatif.", - name_lower = name.to_lowercase())); + return Err(format!( + "Le nombre de {name_lower} ne peut pas être négatif.", + name_lower = name.to_lowercase() + )); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3640: input.publisher_type = clean_work_text(input.publisher_type); - let publisher_type = input.publisher_type.as_deref() - .map(|value| resolve_catalog_key( - connection, - "publisher_types", - "publisher_type_key", - "label", - value, - "Type d'éditeur", - )) + let publisher_type = input + .publisher_type + .as_deref() + .map(|value| { + resolve_catalog_key( + connection, + "publisher_types", + "publisher_type_key", + "label", + value, + "Type d'éditeur", + ) + }) .transpose()?; let mut normalized_adaptations = Vec::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3670: let related_title = clean_work_text(adaptation.related_work_title); - let (related_id, title, form) = match ( - adaptation.related_work_id, - related_title, - ) { + let (related_id, title, form) = match (adaptation.related_work_id, related_title) { (Some(related_id), None) => { - let (title, form): (String, String) = connection.query_row( - "SELECT + let (title, form): (String, String) = connection + .query_row( + "SELECT COALESCE(NULLIF(title_english, ''), title_original), editorial_form FROM works Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3683: WHERE id = ?1", - [related_id], - |row| Ok((row.get(0)?, row.get(1)?)), - ).map_err(|_| { - "La fiche liée sélectionnée n'existe pas.".to_string() - })?; + [related_id], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .map_err(|_| "La fiche liée sélectionnée n'existe pas.".to_string())?; (Some(related_id), title, Some(form)) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3692: (None, Some(title)) => (None, title, None), (Some(_), Some(_)) => { return Err( - "Choisissez une fiche existante ou un titre externe, pas les deux." - .to_string() + "Choisissez une fiche existante ou un titre externe, pas les deux.".to_string(), ); } (None, None) => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3700: - return Err("Le titre ou la fiche de l'œuvre liée est obligatoire." - .to_string()); + return Err("Le titre ou la fiche de l'œuvre liée est obligatoire.".to_string()); } }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3705: - normalized_adaptations.push(( - relation_key, - relation_label, - related_id, - title, - form, - )); + normalized_adaptations.push((relation_key, relation_label, related_id, title, form)); } let status = resolve_catalog_key( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3731: let month = date.get(0..2).and_then(|value| value.parse::().ok()); let year = date.get(3..7).and_then(|value| value.parse::().ok()); - if !valid_format - || !matches!(month, Some(1..=12)) - || !matches!(year, Some(1..)) - { + if !valid_format || !matches!(month, Some(1..=12)) || !matches!(year, Some(1..)) { return Err( "La date de début doit respecter le format MM/AAAA, par exemple 03/2020." - .to_string() + .to_string(), ); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3744: input.original_language = clean_work_text(input.original_language); - let original_language = input.original_language.as_deref() - .map(|value| resolve_catalog_key( - connection, - "original_languages", - "language_key", - "label", - value, - "Langue originale", - )) + let original_language = input + .original_language + .as_deref() + .map(|value| { + resolve_catalog_key( + connection, + "original_languages", + "language_key", + "label", + value, + "Langue originale", + ) + }) .transpose()?; validate_work_link_types(connection, &input.links)?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3763: } } - let transaction = connection.transaction() + let transaction = connection + .transaction() .map_err(|error| error.to_string())?; - transaction.execute( - "INSERT INTO works ( + transaction + .execute( + "INSERT INTO works ( title_original, title_english, romanized, title_french, editorial_form, editorial_subform, author, illustrator, publisher_type, publisher_name, start_date, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3778: ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, ?21 )", - params![ - input.original, - clean_work_text(input.title), - clean_work_text(input.romanized), - clean_work_text(input.french), - form_key, - editorial_subform, - clean_work_text(input.author), - clean_work_text(input.illustrator), - publisher_type, - clean_work_text(input.publisher), - clean_work_text(input.start_date), - input.volumes, - input.chapters, - input.pages, - input.episodes, - input.one_shot, - None::, - None::, - None::, - status, - original_language, - ], - ).map_err(|error| error.to_string())?; + params![ + input.original, + clean_work_text(input.title), + clean_work_text(input.romanized), + clean_work_text(input.french), + form_key, + editorial_subform, + clean_work_text(input.author), + clean_work_text(input.illustrator), + publisher_type, + clean_work_text(input.publisher), + clean_work_text(input.start_date), + input.volumes, + input.chapters, + input.pages, + input.episodes, + input.one_shot, + None::, + None::, + None::, + status, + original_language, + ], + ) + .map_err(|error| error.to_string())?; let work_id = transaction.last_insert_rowid(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3808: // Chaque œuvre possède un conteneur principal unique et isolé. - transaction.execute( - "INSERT INTO work_units + transaction + .execute( + "INSERT INTO work_units (work_id, parent_unit_id, unit_type, label, sort_order) VALUES (?1, NULL, 'work', 'Œuvre', 0)", - [work_id], - ).map_err(|error| error.to_string())?; + [work_id], + ) + .map_err(|error| error.to_string())?; for (direction, label, related_id, title, form) in normalized_adaptations { - transaction.execute( - "INSERT INTO work_adaptations ( + transaction + .execute( + "INSERT INTO work_adaptations ( work_id, direction, relation_label_snapshot, related_work_id, related_work_title, related_work_form ) VALUES (?1, ?2, ?3, ?4, ?5, ?6)", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3822: - params![work_id, direction, label, related_id, title, form], - ).map_err(|error| error.to_string())?; + params![work_id, direction, label, related_id, title, form], + ) + .map_err(|error| error.to_string())?; } - insert_work_names(&transaction, "genres", "work_genres", "genre_id", - work_id, &input.genres)?; - insert_work_names(&transaction, "demographics", "work_demographics", - "demographic_id", work_id, &input.demographics)?; - insert_work_names(&transaction, "tags", "work_tags", "tag_id", - work_id, &input.tags)?; + insert_work_names( + &transaction, + "genres", + "work_genres", + "genre_id", + work_id, + &input.genres, + )?; + insert_work_names( + &transaction, + "demographics", + "work_demographics", + "demographic_id", + work_id, + &input.demographics, + )?; + insert_work_names( + &transaction, + "tags", + "work_tags", + "tag_id", + work_id, + &input.tags, + )?; insert_work_catalog_tags( - &transaction, "secondary_tags", work_id, &form_key, &input.secondary_tags + &transaction, + "secondary_tags", + work_id, + &form_key, + &input.secondary_tags, )?; insert_work_catalog_tags( - &transaction, "erotic_tags", work_id, &form_key, &input.erotic_tags + &transaction, + "erotic_tags", + work_id, + &form_key, + &input.erotic_tags, )?; for translation in input.translations { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3841: - transaction.execute( - "INSERT INTO translations( + transaction + .execute( + "INSERT INTO translations( work_id, language_code, translation_type, chapter_range ) VALUES (?1, ?2, ?3, ?4)", - params![ - work_id, - translation.language_code.trim().to_ascii_lowercase(), - if translation.translation_type.trim().is_empty() { - None - } else { - Some(translation.translation_type.trim()) - }, - clean_work_text(translation.chapter_range), - ], - ).map_err(|error| error.to_string())?; + params![ + work_id, + translation.language_code.trim().to_ascii_lowercase(), + if translation.translation_type.trim().is_empty() { + None + } else { + Some(translation.translation_type.trim()) + }, + clean_work_text(translation.chapter_range), + ], + ) + .map_err(|error| error.to_string())?; } for link in input.links { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3859: - transaction.execute( - "INSERT INTO links(work_id, link_type, label, url) + transaction + .execute( + "INSERT INTO links(work_id, link_type, label, url) VALUES (?1, ?2, ?3, ?4)", - params![work_id, link.link_type, clean_work_text(link.label), link.url.trim()], - ).map_err(|error| error.to_string())?; + params![ + work_id, + link.link_type, + clean_work_text(link.label), + link.url.trim() + ], + ) + .map_err(|error| error.to_string())?; } for source in input.sources { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3867: - transaction.execute( - "INSERT INTO sources(name, url, note) VALUES (?1, ?2, ?3)", - params![ - source.name.trim(), - clean_work_text(source.url), - clean_work_text(source.note) - ], - ).map_err(|error| error.to_string())?; + transaction + .execute( + "INSERT INTO sources(name, url, note) VALUES (?1, ?2, ?3)", + params![ + source.name.trim(), + clean_work_text(source.url), + clean_work_text(source.note) + ], + ) + .map_err(|error| error.to_string())?; let source_id = transaction.last_insert_rowid(); - transaction.execute( - "INSERT INTO work_sources(work_id, source_id) VALUES (?1, ?2)", - params![work_id, source_id], - ).map_err(|error| error.to_string())?; + transaction + .execute( + "INSERT INTO work_sources(work_id, source_id) VALUES (?1, ?2)", + params![work_id, source_id], + ) + .map_err(|error| error.to_string())?; } transaction.commit().map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3886: #[tauri::command] fn list_tags(database: State<'_, Database>) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3903: } #[tauri::command] -fn list_all_tags( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_all_tags(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3913: - let mut statement = connection.prepare( - "SELECT name, is_available FROM tags - ORDER BY is_available DESC, name COLLATE NOCASE" - ).map_err(|error| error.to_string())?; + let mut statement = connection + .prepare( + "SELECT name, is_available FROM tags + ORDER BY is_available DESC, name COLLATE NOCASE", + ) + .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - Ok(TagManagementEntry { - name: row.get(0)?, - is_available: row.get::<_, i64>(1)? != 0, + let rows = statement + .query_map([], |row| { + Ok(TagManagementEntry { + name: row.get(0)?, + is_available: row.get::<_, i64>(1)? != 0, + }) }) - }).map_err(|error| error.to_string())?; + .map_err(|error| error.to_string())?; rows.collect::, _>>() .map_err(|error| error.to_string()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3927: } #[tauri::command] -fn add_or_reactivate_tag( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { +fn add_or_reactivate_tag(name: String, database: State<'_, Database>) -> Result<(), String> { let name = name.trim(); if name.is_empty() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3937: return Err("Le nom du tag ne peut pas être vide.".to_string()); } - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3944: - connection.execute( - "INSERT OR IGNORE INTO tags(name) VALUES (?1)", - [name], - ).map_err(|error| error.to_string())?; + connection + .execute("INSERT OR IGNORE INTO tags(name) VALUES (?1)", [name]) + .map_err(|error| error.to_string())?; - connection.execute( - "UPDATE tags SET is_available = 1 WHERE name = ?1", - [name], - ).map_err(|error| error.to_string())?; + connection + .execute("UPDATE tags SET is_available = 1 WHERE name = ?1", [name]) + .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3956: #[tauri::command] -fn retire_tag( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_tag(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3966: - let changed = connection.execute( - "UPDATE tags SET is_available = 0 WHERE name = ?1", - [name.trim()], - ).map_err(|error| error.to_string())?; + let changed = connection + .execute( + "UPDATE tags SET is_available = 0 WHERE name = ?1", + [name.trim()], + ) + .map_err(|error| error.to_string())?; if changed == 0 { return Err("Tag introuvable.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:3975: Ok(()) } - fn catalog_tag_table(catalog: &str) -> Result<&'static str, String> { match catalog { "secondary_tags" => Ok("secondary_tags"), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4010: .prepare(&sql) .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - Ok(TagManagementEntry { - name: row.get(0)?, - is_available: row.get::<_, i64>(1)? != 0, + let rows = statement + .query_map([], |row| { + Ok(TagManagementEntry { + name: row.get(0)?, + is_available: row.get::<_, i64>(1)? != 0, + }) }) - }).map_err(|error| error.to_string())?; + .map_err(|error| error.to_string())?; rows.collect::, _>>() .map_err(|error| error.to_string()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4033: return Err("Le nom du tag ne peut pas être vide.".to_string()); } - connection.execute( - &format!("INSERT OR IGNORE INTO {table}(name) VALUES (?1)"), - [name], - ).map_err(|error| error.to_string())?; + connection + .execute( + &format!("INSERT OR IGNORE INTO {table}(name) VALUES (?1)"), + [name], + ) + .map_err(|error| error.to_string())?; - connection.execute( - &format!("UPDATE {table} SET is_available = 1 WHERE name = ?1"), - [name], - ).map_err(|error| error.to_string())?; + connection + .execute( + &format!("UPDATE {table} SET is_available = 1 WHERE name = ?1"), + [name], + ) + .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4058: return Err("Le nom du tag ne peut pas être vide.".to_string()); } - let changed = connection.execute( - &format!("UPDATE {table} SET is_available = 0 WHERE name = ?1"), - [name], - ).map_err(|error| error.to_string())?; + let changed = connection + .execute( + &format!("UPDATE {table} SET is_available = 0 WHERE name = ?1"), + [name], + ) + .map_err(|error| error.to_string())?; if changed == 0 { return Err("Tag introuvable.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4071: } #[tauri::command] -fn list_secondary_tags( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_secondary_tags(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4081: - Ok(list_catalog_tags_with_connection( - &connection, "secondary_tags", false - )?.into_iter().map(|entry| entry.name).collect()) + Ok( + list_catalog_tags_with_connection(&connection, "secondary_tags", false)? + .into_iter() + .map(|entry| entry.name) + .collect(), + ) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4087: fn list_all_secondary_tags( database: State<'_, Database>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4099: name: String, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4106: - add_or_reactivate_catalog_tag_with_connection( - &connection, "secondary_tags", &name - ) + add_or_reactivate_catalog_tag_with_connection(&connection, "secondary_tags", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4112: -fn retire_secondary_tag( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_secondary_tag(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4120: - retire_catalog_tag_with_connection( - &connection, "secondary_tags", &name - ) + retire_catalog_tag_with_connection(&connection, "secondary_tags", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4126: -fn list_erotic_tags( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_erotic_tags(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4133: - Ok(list_catalog_tags_with_connection( - &connection, "erotic_tags", false - )?.into_iter().map(|entry| entry.name).collect()) + Ok( + list_catalog_tags_with_connection(&connection, "erotic_tags", false)? + .into_iter() + .map(|entry| entry.name) + .collect(), + ) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4139: -fn list_all_erotic_tags( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_all_erotic_tags(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4147: } #[tauri::command] -fn add_or_reactivate_erotic_tag( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn add_or_reactivate_erotic_tag(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4158: - add_or_reactivate_catalog_tag_with_connection( - &connection, "erotic_tags", &name - ) + add_or_reactivate_catalog_tag_with_connection(&connection, "erotic_tags", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4164: -fn retire_erotic_tag( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_erotic_tag(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4172: - retire_catalog_tag_with_connection( - &connection, "erotic_tags", &name - ) + retire_catalog_tag_with_connection(&connection, "erotic_tags", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4180: database: State<'_, Database>, associations: State<'_, FileAssociationsState>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4196: return Err("Cette œuvre n'existe pas.".to_string()); } - let _guard = associations.lock + let _guard = associations + .lock .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4209: label, sort_order, created_at, updated_at, is_retired FROM work_units WHERE work_id = ?1 - ORDER BY sort_order, id" + ORDER BY sort_order, id", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4236: let mut result = Vec::with_capacity(units.len()); for unit in units { - let files = document.associations.iter() + let files = document + .associations + .iter() .filter(|association| { - association.work_id == work_id - && association.unit_id == Some(unit.0) + association.work_id == work_id && association.unit_id == Some(unit.0) }) .map(|association| UnitFile { id: association.id, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4269: Ok(result) } - - #[tauri::command] fn create_work_unit( work_id: i64, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4280: sort_order: i64, database: State<'_, Database>, ) -> Result { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4287: create_work_unit_with_connection( - &connection, work_id, parent_unit_id, - unit_type, label, sort_order + &connection, + work_id, + parent_unit_id, + unit_type, + label, + sort_order, ) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4296: unit_id: i64, retired: bool, ) -> Result<(), String> { - let exists: bool = connection.query_row( - "SELECT EXISTS( + let exists: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM work_units WHERE id = ?1 AND work_id = ?2 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4304: AND unit_type != 'work' )", - rusqlite::params![unit_id, work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![unit_id, work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !exists { - return Err( - "Unité introuvable dans cette œuvre ou opération interdite." - .to_string() - ); + return Err("Unité introuvable dans cette œuvre ou opération interdite.".to_string()); } - connection.execute( - "UPDATE work_units + connection + .execute( + "UPDATE work_units SET is_retired = ?1, updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE id = ?2 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4322: AND work_id = ?3 AND unit_type != 'work' AND is_retired != ?1", - rusqlite::params![retired, unit_id, work_id], - ).map_err(|error| error.to_string())?; + rusqlite::params![retired, unit_id, work_id], + ) + .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4333: work_id: i64, retired: bool, ) -> Result { - let work_exists: bool = connection.query_row( - "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", - [work_id], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + let work_exists: bool = connection + .query_row( + "SELECT EXISTS(SELECT 1 FROM works WHERE id = ?1)", + [work_id], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !work_exists { return Err("Cette œuvre n'existe pas.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4344: } - let changed = connection.execute( - "UPDATE work_units + let changed = connection + .execute( + "UPDATE work_units SET is_retired = ?1, updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE work_id = ?2 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4351: AND unit_type != 'work' AND is_retired != ?1", - rusqlite::params![retired, work_id], - ).map_err(|error| error.to_string())?; + rusqlite::params![retired, work_id], + ) + .map_err(|error| error.to_string())?; Ok(changed) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4363: retired: bool, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4370: - set_work_unit_retired_with_connection( - &connection, work_id, unit_id, retired - ) + set_work_unit_retired_with_connection(&connection, work_id, unit_id, retired) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4378: retired: bool, database: State<'_, Database>, ) -> Result { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4385: - set_all_work_units_retired_with_connection( - &connection, work_id, retired - ) + set_all_work_units_retired_with_connection(&connection, work_id, retired) } fn create_work_unit_with_connection( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4427: .map_err(|error| error.to_string())?; if !type_available { - return Err("Type d'unité inconnu, indisponible ou réservé au conteneur principal." - .to_string()); + return Err( + "Type d'unité inconnu, indisponible ou réservé au conteneur principal.".to_string(), + ); } // Récupération de la forme et du sous-format éditorial de l'œuvre. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4473: if !editorial_type_allowed { return Err( "Ce type d'unité n'est pas autorisé pour la forme ou le sous-format de cette œuvre." - .to_string() + .to_string(), ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4517: if !parent_exists { return Err( "L'unité parente est introuvable, retirée ou ne peut pas servir de parent." - .to_string() + .to_string(), ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4549: if !parent_rule_allowed { return Err( "Cette relation parent-enfant n'est pas autorisée par le catalogue." - .to_string() + .to_string(), ); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4556: } - connection.execute( - "INSERT INTO work_units + connection + .execute( + "INSERT INTO work_units (work_id, parent_unit_id, unit_type, label, sort_order) VALUES (?1, ?2, ?3, ?4, ?5)", - rusqlite::params![ - work_id, parent_unit_id, unit_type, label, sort_order - ], - ).map_err(|error| error.to_string())?; + rusqlite::params![work_id, parent_unit_id, unit_type, label, sort_order], + ) + .map_err(|error| error.to_string())?; Ok(connection.last_insert_rowid()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4598: } if let Err(error) = connection.execute_batch("PRAGMA foreign_keys = ON;") { - cleanup_errors.push(format!("réactivation des clés étrangères impossible : {error}")); + cleanup_errors.push(format!( + "réactivation des clés étrangères impossible : {error}" + )); } match connection.query_row("PRAGMA foreign_keys", [], |row| row.get::<_, i64>(0)) { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:4988: .prepare( "SELECT relation_key, label, inverse_key, is_available FROM relation_types - ORDER BY label COLLATE NOCASE" + ORDER BY label COLLATE NOCASE", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5012: } #[tauri::command] -fn list_relation_types( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_relation_types(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5023: } #[tauri::command] -fn list_genres( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_genres(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5033: - Ok(list_catalog_tags_with_connection( - &connection, "genres", false - )?.into_iter().map(|entry| entry.name).collect()) + Ok( + list_catalog_tags_with_connection(&connection, "genres", false)? + .into_iter() + .map(|entry| entry.name) + .collect(), + ) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5039: -fn list_all_genres( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_all_genres(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5047: } #[tauri::command] -fn add_or_reactivate_genre( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn add_or_reactivate_genre(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5058: - add_or_reactivate_catalog_tag_with_connection( - &connection, "genres", &name - ) + add_or_reactivate_catalog_tag_with_connection(&connection, "genres", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5064: -fn retire_genre( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_genre(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5073: } #[tauri::command] -fn list_demographics( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_demographics(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5083: - Ok(list_catalog_tags_with_connection( - &connection, "demographics", false - )?.into_iter().map(|entry| entry.name).collect()) + Ok( + list_catalog_tags_with_connection(&connection, "demographics", false)? + .into_iter() + .map(|entry| entry.name) + .collect(), + ) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5089: -fn list_all_demographics( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_all_demographics(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5101: name: String, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5108: - add_or_reactivate_catalog_tag_with_connection( - &connection, "demographics", &name - ) + add_or_reactivate_catalog_tag_with_connection(&connection, "demographics", &name) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5114: -fn retire_demographic( - name: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_demographic(name: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5122: retire_catalog_tag_with_connection(&connection, "demographics", &name) } - fn load_catalog_entries( connection: &Connection, table: &str, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5155: } #[tauri::command] -fn list_editorial_forms( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_editorial_forms(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5166: } #[tauri::command] -fn list_erotic_tag_forms( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_erotic_tag_forms(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5179: FROM form_erotic_tags fet JOIN editorial_forms ef ON ef.form_key = fet.form_key WHERE ef.is_available = 1 - ORDER BY ef.label COLLATE NOCASE" + ORDER BY ef.label COLLATE NOCASE", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5195: fn list_editorial_subforms( database: State<'_, Database>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5207: ON ef.form_key = efs.form_key JOIN editorial_subforms es ON es.subform_key = efs.subform_key - ORDER BY ef.label COLLATE NOCASE, es.label COLLATE NOCASE" + ORDER BY ef.label COLLATE NOCASE, es.label COLLATE NOCASE", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5227: } #[tauri::command] -fn list_original_languages( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_original_languages(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5238: } #[tauri::command] -fn list_publisher_types( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_publisher_types(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5249: } #[tauri::command] -fn list_work_statuses( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_work_statuses(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5265: let valid = !bytes.is_empty() && bytes[0].is_ascii_lowercase() && bytes.iter().all(|byte| { - byte.is_ascii_lowercase() - || byte.is_ascii_digit() - || *byte == b'_' - || *byte == b'-' + byte.is_ascii_lowercase() || byte.is_ascii_digit() || *byte == b'_' || *byte == b'-' }); if !valid { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5281: Ok(()) } -fn list_link_types_with_connection( - connection: &Connection, -) -> Result, String> { +fn list_link_types_with_connection(connection: &Connection) -> Result, String> { load_catalog_entries(connection, "link_types", "link_type_key") } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5301: return Err("Le libellé du type de lien ne peut pas être vide.".to_string()); } - let label_conflict: bool = connection.query_row( - "SELECT EXISTS( + let label_conflict: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM link_types WHERE label = ?1 AND link_type_key <> ?2 )", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5309: - rusqlite::params![label, key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![label, key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if label_conflict { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5317: )); } - connection.execute( - "INSERT INTO link_types(link_type_key, label, is_available) + connection + .execute( + "INSERT INTO link_types(link_type_key, label, is_available) VALUES (?1, ?2, 1) ON CONFLICT(link_type_key) DO UPDATE SET label = excluded.label, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5325: is_available = 1", - rusqlite::params![key, label], - ).map_err(|error| error.to_string())?; + rusqlite::params![key, label], + ) + .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5331: -fn retire_link_type_with_connection( - connection: &Connection, - key: &str, -) -> Result<(), String> { +fn retire_link_type_with_connection(connection: &Connection, key: &str) -> Result<(), String> { let key = key.trim(); if key.is_empty() { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5339: return Err("La clé du type de lien ne peut pas être vide.".to_string()); } - let changed = connection.execute( - "UPDATE link_types SET is_available = 0 + let changed = connection + .execute( + "UPDATE link_types SET is_available = 0 WHERE link_type_key = ?1", - [key], - ).map_err(|error| error.to_string())?; + [key], + ) + .map_err(|error| error.to_string())?; if changed == 0 { return Err("Type de lien introuvable.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5357: links: &[CreateWorkLink], ) -> Result<(), String> { for link in links { - let available: bool = connection.query_row( - "SELECT EXISTS( + let available: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM link_types WHERE link_type_key = ?1 AND is_available = 1 )", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5365: - [link.link_type.trim()], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + [link.link_type.trim()], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !available { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5387: let valid = !bytes.is_empty() && bytes[0].is_ascii_lowercase() && bytes.iter().all(|byte| { - byte.is_ascii_lowercase() - || byte.is_ascii_digit() - || *byte == b'_' - || *byte == b'-' + byte.is_ascii_lowercase() || byte.is_ascii_digit() || *byte == b'_' || *byte == b'-' }); if !valid { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5423: return Err("Le libellé du type de traduction ne peut pas être vide.".to_string()); } - let label_conflict: bool = connection.query_row( - "SELECT EXISTS( + let label_conflict: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM translation_types WHERE label = ?1 AND translation_type_key <> ?2 )", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5431: - rusqlite::params![label, key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![label, key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if label_conflict { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5439: )); } - connection.execute( - "INSERT INTO translation_types( + connection + .execute( + "INSERT INTO translation_types( translation_type_key, label, is_available ) VALUES (?1, ?2, 1) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5447: ON CONFLICT(translation_type_key) DO UPDATE SET label = excluded.label, is_available = 1", - rusqlite::params![key, label], - ).map_err(|error| error.to_string())?; + rusqlite::params![key, label], + ) + .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5463: return Err("La clé du type de traduction ne peut pas être vide.".to_string()); } - let changed = connection.execute( - "UPDATE translation_types + let changed = connection + .execute( + "UPDATE translation_types SET is_available = 0 WHERE translation_type_key = ?1", - [key], - ).map_err(|error| error.to_string())?; + [key], + ) + .map_err(|error| error.to_string())?; if changed == 0 { return Err("Type de traduction introuvable.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5481: let mut parts = key.split('-'); let primary = parts.next().unwrap_or(""); - let valid_primary = (2..=3).contains(&primary.len()) - && primary.bytes().all(|byte| byte.is_ascii_lowercase()); + let valid_primary = + (2..=3).contains(&primary.len()) && primary.bytes().all(|byte| byte.is_ascii_lowercase()); let valid_subtags = parts.clone().all(|part| { (2..=8).contains(&part.len()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5489: - && part.bytes().all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit()) + && part + .bytes() + .all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit()) }); if !valid_primary || !valid_subtags || parts.clone().count() == 0 && key.contains('-') { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5502: fn list_translation_languages_with_connection( connection: &Connection, ) -> Result, String> { - let mut statement = connection.prepare( - "SELECT + let mut statement = connection + .prepare( + "SELECT l.language_code, l.label, l.is_available, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5513: FROM translation_languages l JOIN translation_settings s ON s.language_code = l.language_code - ORDER BY l.label COLLATE NOCASE" - ).map_err(|error| error.to_string())?; + ORDER BY l.label COLLATE NOCASE", + ) + .map_err(|error| error.to_string())?; - let rows = statement.query_map([], |row| { - Ok(TranslationLanguageEntry { - key: row.get(0)?, - label: row.get(1)?, - active: row.get::<_, i64>(2)? != 0, - is_tracked: row.get::<_, i64>(3)? != 0, - allow_type: row.get::<_, i64>(4)? != 0, - allow_chapter_range: row.get::<_, i64>(5)? != 0, + let rows = statement + .query_map([], |row| { + Ok(TranslationLanguageEntry { + key: row.get(0)?, + label: row.get(1)?, + active: row.get::<_, i64>(2)? != 0, + is_tracked: row.get::<_, i64>(3)? != 0, + allow_type: row.get::<_, i64>(4)? != 0, + allow_chapter_range: row.get::<_, i64>(5)? != 0, + }) }) - }).map_err(|error| error.to_string())?; + .map_err(|error| error.to_string())?; rows.collect::, _>>() .map_err(|error| error.to_string()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5545: return Err("Le libellé de la langue de traduction ne peut pas être vide.".to_string()); } - connection.execute_batch("SAVEPOINT add_translation_language") + connection + .execute_batch("SAVEPOINT add_translation_language") .map_err(|error| error.to_string())?; let result = (|| -> Result<(), String> { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5552: - let label_conflict: bool = connection.query_row( - "SELECT EXISTS( + let label_conflict: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM translation_languages WHERE lower(trim(label)) = lower(?1) AND language_code <> ?2 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5557: )", - rusqlite::params![label, key], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + rusqlite::params![label, key], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if label_conflict { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5566: )); } - connection.execute( - "INSERT INTO translation_languages( + connection + .execute( + "INSERT INTO translation_languages( language_code, label, is_available ) VALUES (?1, ?2, 1) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5574: ON CONFLICT(language_code) DO UPDATE SET label = excluded.label, is_available = 1", - rusqlite::params![key, label], - ).map_err(|error| error.to_string())?; + rusqlite::params![key, label], + ) + .map_err(|error| error.to_string())?; - connection.execute( - "INSERT OR IGNORE INTO translation_settings( + connection + .execute( + "INSERT OR IGNORE INTO translation_settings( language_code, is_tracked, allow_type, allow_chapter_range ) VALUES (?1, 0, 1, 1)", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5585: - [&key], - ).map_err(|error| error.to_string())?; + [&key], + ) + .map_err(|error| error.to_string())?; Ok(()) })(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5590: match result { Ok(()) => { - connection.execute_batch("RELEASE SAVEPOINT add_translation_language") + connection + .execute_batch("RELEASE SAVEPOINT add_translation_language") .map_err(|error| error.to_string())?; Ok(()) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5597: Err(error) => { let _ = connection.execute_batch( "ROLLBACK TO SAVEPOINT add_translation_language; - RELEASE SAVEPOINT add_translation_language;" + RELEASE SAVEPOINT add_translation_language;", ); Err(error) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5612: validate_translation_language_code(&key)?; - let changed = connection.execute( - "UPDATE translation_languages + let changed = connection + .execute( + "UPDATE translation_languages SET is_available = 0 WHERE language_code = ?1", - [&key], - ).map_err(|error| error.to_string())?; + [&key], + ) + .map_err(|error| error.to_string())?; if changed == 0 { return Err("Langue de traduction introuvable.".to_string()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5630: fn list_translation_languages( database: State<'_, Database>, ) -> Result, String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5643: label: String, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5650: - add_or_reactivate_translation_language_with_connection( - &connection, &key, &label - ) + add_or_reactivate_translation_language_with_connection(&connection, &key, &label) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5656: -fn retire_translation_language( - key: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_translation_language(key: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5677: return Err("La langue d'une traduction ne peut pas être vide.".to_string()); } - let settings: Option<(i64, i64, i64)> = connection.query_row( - "SELECT + let settings: Option<(i64, i64, i64)> = connection + .query_row( + "SELECT l.is_available, s.allow_type, s.allow_chapter_range Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5686: JOIN translation_settings s ON s.language_code = l.language_code WHERE l.language_code = ?1", - [&language_code], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).optional().map_err(|error| error.to_string())?; + [&language_code], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .optional() + .map_err(|error| error.to_string())?; - let (is_available, allow_type, allow_chapter_range) = settings - .ok_or_else(|| format!( + let (is_available, allow_type, allow_chapter_range) = settings.ok_or_else(|| { + format!( "La langue de traduction « {} » n'existe pas ou ne possède pas de paramètres.", language_code - ))?; + ) + })?; if is_available == 0 { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5714: )); } - let available: bool = connection.query_row( - "SELECT EXISTS( + let available: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM translation_types WHERE translation_type_key = ?1 AND is_available = 1 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5722: )", - [translation_type], - |row| row.get(0), - ).map_err(|error| error.to_string())?; + [translation_type], + |row| row.get(0), + ) + .map_err(|error| error.to_string())?; if !available { return Err(format!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5734: Some(translation_type.to_string()) }; - let chapter_range = translation.chapter_range + let chapter_range = translation + .chapter_range .as_deref() .map(str::trim) .filter(|value| !value.is_empty()) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5747: )); } - let signature = ( - language_code, - normalized_type, - chapter_range, - ); + let signature = (language_code, normalized_type, chapter_range); if !seen.insert(signature) { return Err( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5758: - "Cette entrée de traduction est déjà renseignée à l'identique.".to_string() + "Cette entrée de traduction est déjà renseignée à l'identique.".to_string(), ); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5764: } #[tauri::command] -fn list_translation_types( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_translation_types(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5780: label: String, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5787: - add_or_reactivate_translation_type_with_connection( - &connection, &key, &label - ) + add_or_reactivate_translation_type_with_connection(&connection, &key, &label) } #[tauri::command] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5793: -fn retire_translation_type( - key: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_translation_type(key: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5802: } #[tauri::command] -fn list_link_types( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_link_types(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5818: label: String, database: State<'_, Database>, ) -> Result<(), String> { - let connection = database.connection + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5826: } #[tauri::command] -fn retire_link_type( - key: String, - database: State<'_, Database>, -) -> Result<(), String> { - let connection = database.connection +fn retire_link_type(key: String, database: State<'_, Database>) -> Result<(), String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5838: } #[tauri::command] -fn list_unit_types( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_unit_types(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5849: .prepare( "SELECT unit_type, label, is_available, is_main FROM unit_types - ORDER BY is_main DESC, label COLLATE NOCASE" + ORDER BY is_main DESC, label COLLATE NOCASE", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5907: } #[tauri::command] -fn list_unit_rules( - database: State<'_, Database>, -) -> Result { - let connection = database.connection +fn list_unit_rules(database: State<'_, Database>) -> Result { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5919: .prepare( "SELECT form_key, unit_type FROM form_unit_types - ORDER BY form_key, unit_type" + ORDER BY form_key, unit_type", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5941: .prepare( "SELECT form_key, subform_key, unit_type FROM subform_unit_types - ORDER BY form_key, subform_key, unit_type" + ORDER BY form_key, subform_key, unit_type", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5964: .prepare( "SELECT form_key, unit_type FROM unit_root_types - ORDER BY form_key, unit_type" + ORDER BY form_key, unit_type", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:5986: .prepare( "SELECT parent_unit_type, child_unit_type FROM unit_parent_rules - ORDER BY parent_unit_type, child_unit_type" + ORDER BY parent_unit_type, child_unit_type", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6030: "SELECT form_key, subform_key, counter_kind, fallback_unit_type, short_max, medium_max FROM work_size_rules - ORDER BY form_key, subform_key" + ORDER BY form_key, subform_key", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6052: } #[tauri::command] -fn list_work_size_rules( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_work_size_rules(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6070: } #[tauri::command] -fn list_form_one_shot_rules( - database: State<'_, Database>, -) -> Result, String> { - let connection = database.connection +fn list_form_one_shot_rules(database: State<'_, Database>) -> Result, String> { + let connection = database + .connection .lock() .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6081: .prepare( "SELECT form_key, allowed FROM form_one_shot_rules - ORDER BY form_key" + ORDER BY form_key", ) .map_err(|error| error.to_string())?; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6150: } fn finish(&mut self) { - let has_errors = self.diagnostics - .iter() - .any(|item| item.severity == "error"); + let has_errors = self.diagnostics.iter().any(|item| item.severity == "error"); - let has_warnings = self.diagnostics + let has_warnings = self + .diagnostics .iter() .any(|item| item.severity == "warning"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6191: return false; } - let Some(year) = digits(0, 4) else { return false }; - let Some(month) = digits(5, 7) else { return false }; - let Some(day) = digits(8, 10) else { return false }; - let Some(hour) = digits(11, 13) else { return false }; - let Some(minute) = digits(14, 16) else { return false }; - let Some(second) = digits(17, 19) else { return false }; + let Some(year) = digits(0, 4) else { + return false; + }; + let Some(month) = digits(5, 7) else { + return false; + }; + let Some(day) = digits(8, 10) else { + return false; + }; + let Some(hour) = digits(11, 13) else { + return false; + }; + let Some(minute) = digits(14, 16) else { + return false; + }; + let Some(second) = digits(17, 19) else { + return false; + }; - if year == 0 || !(1..=12).contains(&month) - || hour > 23 || minute > 59 || second > 59 - { + if year == 0 || !(1..=12).contains(&month) || hour > 23 || minute > 59 || second > 59 { return false; } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6251: return false; }; - offset_hour <= 14 - && offset_minute <= 59 - && (offset_hour < 14 || offset_minute == 0) + offset_hour <= 14 && offset_minute <= 59 && (offset_hour < 14 || offset_minute == 0) } - fn portable_json_string<'a>(value: &'a serde_json::Value, key: &str) -> Option<&'a str> { value.get(key).and_then(serde_json::Value::as_str) } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6328: "CATEGORY_PATH_WRONG_TYPE", format!( "Le chemin de « {category} » n'est pas du type attendu ({}).", - if expected_directory { "dossier" } else { "fichier" } + if expected_directory { + "dossier" + } else { + "fichier" + } ), Some(relative_path.to_string()), ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6531: "suppressions", ]; - let read_category_list = |key: &str, - result: &mut PortableLibraryAnalysisResult| - -> Vec { - match contents.get(key).and_then(Value::as_array) { - Some(items) => { - let mut output = Vec::new(); - for item in items { - match item.as_str() { - Some(category) => output.push(category.to_string()), - None => result.add( - "error", - "CATEGORY_NAME_INVALID", - format!("Une entrée de contents.{key} n'est pas une chaîne."), - Some(format!("contents.{key}")), - ), + let read_category_list = + |key: &str, result: &mut PortableLibraryAnalysisResult| -> Vec { + match contents.get(key).and_then(Value::as_array) { + Some(items) => { + let mut output = Vec::new(); + for item in items { + match item.as_str() { + Some(category) => output.push(category.to_string()), + None => result.add( + "error", + "CATEGORY_NAME_INVALID", + format!("Une entrée de contents.{key} n'est pas une chaîne."), + Some(format!("contents.{key}")), + ), + } } + output } - output + None => { + result.add( + "error", + "CATEGORY_LIST_MISSING", + format!("La liste contents.{key} est absente ou invalide."), + Some(format!("contents.{key}")), + ); + Vec::new() + } } - None => { - result.add( - "error", - "CATEGORY_LIST_MISSING", - format!("La liste contents.{key} est absente ou invalide."), - Some(format!("contents.{key}")), - ); - Vec::new() - } - } - }; + }; result.included_categories = read_category_list("included", &mut result); result.excluded_categories = read_category_list("excluded", &mut result); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6618: } } - let included: HashSet = - result.included_categories.iter().cloned().collect(); + let included: HashSet = result.included_categories.iter().cloned().collect(); let ordinary_categories = [ ("works", true), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:6637: for (category, is_directory) in ordinary_categories { if included.contains(category) { - if let Some(path) = portable_check_category_path( - &mut result, - root, - contents, - category, - is_directory, - ) { + if let Some(path) = + portable_check_category_path(&mut result, root, contents, category, is_directory) + { category_paths.insert(category.to_string(), path); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7147: analyze_portable_library_internal(&root) } - -fn portable_safe_path( - root: &Path, - relative_path: &str, -) -> Result { +fn portable_safe_path(root: &Path, relative_path: &str) -> Result { let relative = Path::new(relative_path); if relative_path.trim().is_empty() Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7158: - || relative.components().all(|component| { - matches!(component, std::path::Component::CurDir) - }) + || relative + .components() + .all(|component| matches!(component, std::path::Component::CurDir)) || relative.is_absolute() || relative.components().any(|component| { matches!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7182: Ok(metadata) => { if metadata.file_type().is_symlink() { return Err( - "Le chemin contient un lien symbolique ; accès refusé." - .to_string() + "Le chemin contient un lien symbolique ; accès refusé.".to_string() ); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7201: } if candidate.exists() { - let canonical_root = root.canonicalize() + let canonical_root = root + .canonicalize() .map_err(|error| format!("Dossier portable inaccessible : {error}"))?; - let canonical_candidate = candidate.canonicalize() + let canonical_candidate = candidate + .canonicalize() .map_err(|error| format!("Chemin inaccessible : {error}"))?; if canonical_candidate == canonical_root { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7211: return Err( - "Le chemin désigne la racine du dossier portable ; accès refusé." - .to_string() + "Le chemin désigne la racine du dossier portable ; accès refusé.".to_string(), ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7277: return Err("Le nom doit contenir entre 1 et 120 caractères.".into()); } - if clean_name == "." || clean_name == ".." - || clean_name.chars().any(|character| { - character == '/' || character == '\\' || character.is_control() - }) + if clean_name == "." + || clean_name == ".." + || clean_name + .chars() + .any(|character| character == '/' || character == '\\' || character.is_control()) { return Err("Le nom contient des caractères interdits.".into()); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7287: validate_portable_uuid_v4(&library_uuid)?; - if created_at.len() < 20 - || !created_at.contains('T') - || !created_at.ends_with('Z') - { + if created_at.len() < 20 || !created_at.contains('T') || !created_at.ends_with('Z') { return Err("Date de création ISO 8601 invalide.".into()); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7308: return Err("Un élément portant déjà ce nom existe dans ce dossier. Aucun fichier n'a été remplacé.".into()); } - let staging_path = parent.join(format!( - ".bibliotheca-portable-{}.tmp", - library_uuid - )); + let staging_path = parent.join(format!(".bibliotheca-portable-{}.tmp", library_uuid)); if staging_path.exists() { return Err("Un dossier temporaire portant cet identifiant existe déjà.".into()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7431: connection.execute_batch("PRAGMA foreign_keys = ON;")?; - let schema_version = initialize_database(&connection) - .map_err(std::io::Error::other)?; + let schema_version = initialize_database(&connection).map_err(std::io::Error::other)?; println!( "Bibliotheca SQLite initialisée : {} (schéma {})", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7448: let associations_path = test_root.join("associations-fichiers.json"); let downloads_path = test_root.join("Téléchargements"); - let storage_roots = initialize_storage_roots(&test_root) - .map_err(std::io::Error::other)?; + let storage_roots = + initialize_storage_roots(&test_root).map_err(std::io::Error::other)?; app.manage(FileAssociationsState { path: associations_path, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7531: .expect("Erreur pendant le démarrage de Bibliotheca"); } - #[cfg(test)] mod tests { use super::*; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7626: }; let config_path = root.join("configuration/storage-roots.json"); - std::fs::write(&config_path, serde_json::to_vec_pretty(&document).unwrap()) - .unwrap(); + std::fs::write(&config_path, serde_json::to_vec_pretty(&document).unwrap()).unwrap(); let state = initialize_storage_roots(&root).unwrap(); assert_eq!(state.roots.len(), 2); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7711: } ] }"#, - ).unwrap(); + ) + .unwrap(); let mut document = read_file_associations(&path).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7828: }; let connection = test_connection(); - let status = make_work_file_limit_status( - &connection, - "manga", - 1, - &document, - ).unwrap(); + let status = make_work_file_limit_status(&connection, "manga", 1, &document).unwrap(); assert_eq!(status.current_count, 3); assert_eq!(status.default_limit, 1000); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7855: let connection = test_connection(); let associations = FileAssociationsDocument::default(); - assert_eq!( - custom_work_file_limit(&connection, 1).unwrap(), - None - ); + assert_eq!(custom_work_file_limit(&connection, 1).unwrap(), None); - let status = make_work_file_limit_status( - &connection, - "manga", - 1, - &associations, - ).unwrap(); + let status = make_work_file_limit_status(&connection, "manga", 1, &associations).unwrap(); assert_eq!(status.default_limit, 1000); assert_eq!(status.active_limit, 1000); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7878: let connection = test_connection(); let associations = FileAssociationsDocument::default(); - connection.execute( - "INSERT INTO work_file_limit_overrides (work_id, custom_limit) + connection + .execute( + "INSERT INTO work_file_limit_overrides (work_id, custom_limit) VALUES (1, 1500)", - [], - ).unwrap(); + [], + ) + .unwrap(); - assert_eq!( - custom_work_file_limit(&connection, 1).unwrap(), - Some(1500) - ); + assert_eq!(custom_work_file_limit(&connection, 1).unwrap(), Some(1500)); - let status = make_work_file_limit_status( - &connection, - "manga", - 1, - &associations, - ).unwrap(); + let status = make_work_file_limit_status(&connection, "manga", 1, &associations).unwrap(); assert_eq!(status.default_limit, 1000); assert_eq!(status.active_limit, 1500); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7906: fn work_file_limit_override_can_be_updated_and_removed() { let connection = test_connection(); - connection.execute( - "INSERT INTO work_file_limit_overrides (work_id, custom_limit) + connection + .execute( + "INSERT INTO work_file_limit_overrides (work_id, custom_limit) VALUES (1, 1500)", - [], - ).unwrap(); + [], + ) + .unwrap(); - connection.execute( - "INSERT INTO work_file_limit_overrides (work_id, custom_limit) + connection + .execute( + "INSERT INTO work_file_limit_overrides (work_id, custom_limit) VALUES (1, 1800) ON CONFLICT(work_id) DO UPDATE SET custom_limit = excluded.custom_limit", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7920: - [], - ).unwrap(); + [], + ) + .unwrap(); - assert_eq!( - custom_work_file_limit(&connection, 1).unwrap(), - Some(1800) - ); + assert_eq!(custom_work_file_limit(&connection, 1).unwrap(), Some(1800)); - connection.execute( - "DELETE FROM work_file_limit_overrides WHERE work_id = ?1", - [1], - ).unwrap(); + connection + .execute( + "DELETE FROM work_file_limit_overrides WHERE work_id = ?1", + [1], + ) + .unwrap(); - assert_eq!( - custom_work_file_limit(&connection, 1).unwrap(), - None - ); + assert_eq!(custom_work_file_limit(&connection, 1).unwrap(), None); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7961: fn work_file_limit_override_is_deleted_with_its_work() { let connection = test_connection(); - connection.execute( - "INSERT INTO work_file_limit_overrides (work_id, custom_limit) + connection + .execute( + "INSERT INTO work_file_limit_overrides (work_id, custom_limit) VALUES (4, 3000)", - [], - ).unwrap(); + [], + ) + .unwrap(); - connection.execute( - "DELETE FROM works WHERE id = ?1", - [4], - ).unwrap(); + connection + .execute("DELETE FROM works WHERE id = ?1", [4]) + .unwrap(); - let remaining: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_file_limit_overrides + let remaining: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_file_limit_overrides WHERE work_id = 4", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(remaining, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:7987: let connection = test_connection(); add_or_reactivate_translation_type_with_connection( - &connection, "subtitle", "Traduction sous-titrée" - ).unwrap(); + &connection, + "subtitle", + "Traduction sous-titrée", + ) + .unwrap(); let entries = list_translation_types_with_connection(&connection).unwrap(); - let entry = entries.iter() + let entry = entries + .iter() .find(|entry| entry.key == "subtitle") .unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8006: for key in ["", "Official", "bad key", "_bad", "bad.key"] { assert!( add_or_reactivate_translation_type_with_connection( - &connection, key, "Libellé valide" - ).is_err(), + &connection, + key, + "Libellé valide" + ) + .is_err(), "La clé {key:?} aurait dû être refusée" ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8014: - assert!( - add_or_reactivate_translation_type_with_connection( - &connection, "valid_key", " " - ).is_err() - ); + assert!(add_or_reactivate_translation_type_with_connection( + &connection, + "valid_key", + " " + ) + .is_err()); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8024: let connection = test_connection(); let result = add_or_reactivate_translation_type_with_connection( - &connection, "custom_translation", "Traduction officielle" + &connection, + "custom_translation", + "Traduction officielle", ); assert!(result.is_err()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8031: - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM translation_types + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM translation_types WHERE translation_type_key = 'custom_translation'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8043: fn translation_type_management_retires_without_deleting_history() { let connection = test_connection(); - connection.execute( - "INSERT INTO translations + connection + .execute( + "INSERT INTO translations (work_id, language_code, translation_type, chapter_range) VALUES (1, 'en', 'official', '1-25')", - [], - ).unwrap(); + [], + ) + .unwrap(); - retire_translation_type_with_connection( - &connection, "official" - ).unwrap(); + retire_translation_type_with_connection(&connection, "official").unwrap(); - let stored: (String, String, Option) = connection.query_row( - "SELECT language_code, translation_type, chapter_range + let stored: (String, String, Option) = connection + .query_row( + "SELECT language_code, translation_type, chapter_range FROM translations WHERE work_id = 1", - [], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(stored.0, "en"); assert_eq!(stored.1, "official"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8067: let entries = list_translation_types_with_connection(&connection).unwrap(); assert!( - !entries.iter().find(|entry| entry.key == "official").unwrap().active + !entries + .iter() + .find(|entry| entry.key == "official") + .unwrap() + .active ); let works = list_works_with_connection(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8086: fn translation_type_management_reactivates_existing_type() { let connection = test_connection(); - retire_translation_type_with_connection( - &connection, "official" - ).unwrap(); + retire_translation_type_with_connection(&connection, "official").unwrap(); add_or_reactivate_translation_type_with_connection( - &connection, "official", "Traduction officielle" - ).unwrap(); + &connection, + "official", + "Traduction officielle", + ) + .unwrap(); let entries = list_translation_types_with_connection(&connection).unwrap(); - let entry = entries.iter() + let entry = entries + .iter() .find(|entry| entry.key == "official") .unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8102: assert_eq!(entry.label, "Traduction officielle"); assert!(entry.active); - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM translation_types + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM translation_types WHERE translation_type_key = 'official'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 1); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8116: fn translation_language_management_adds_language_and_default_settings() { let connection = test_connection(); - add_or_reactivate_translation_language_with_connection( - &connection, "ja", "Japonais" - ).unwrap(); + add_or_reactivate_translation_language_with_connection(&connection, "ja", "Japonais") + .unwrap(); let entries = list_translation_languages_with_connection(&connection).unwrap(); let entry = entries.iter().find(|entry| entry.key == "ja").unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8126: assert_eq!(entry.label, "Japonais"); assert!(entry.active); - let settings: (i64, i64, i64) = connection.query_row( - "SELECT is_tracked, allow_type, allow_chapter_range + let settings: (i64, i64, i64) = connection + .query_row( + "SELECT is_tracked, allow_type, allow_chapter_range FROM translation_settings WHERE language_code = 'ja'", - [], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(settings, (0, 1, 1)); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8141: let connection = test_connection(); add_or_reactivate_translation_language_with_connection( - &connection, "PT-BR", "Portugais brésilien" - ).unwrap(); + &connection, + "PT-BR", + "Portugais brésilien", + ) + .unwrap(); - let exists: bool = connection.query_row( - "SELECT EXISTS( + let exists: bool = connection + .query_row( + "SELECT EXISTS( SELECT 1 FROM translation_languages WHERE language_code = 'pt-br' )", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8152: - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert!(exists); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8158: for key in ["", "e", "English", "pt_BR", "ja--jp", "bad code", "éé"] { assert!( add_or_reactivate_translation_language_with_connection( - &connection, key, "Libellé valide" - ).is_err(), + &connection, + key, + "Libellé valide" + ) + .is_err(), "Le code {key:?} aurait dû être refusé" ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8166: assert!( - add_or_reactivate_translation_language_with_connection( - &connection, "ko", " " - ).is_err() + add_or_reactivate_translation_language_with_connection(&connection, "ko", " ") + .is_err() ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8175: fn translation_language_management_rejects_duplicate_label() { let connection = test_connection(); - let result = add_or_reactivate_translation_language_with_connection( - &connection, "ja", "anglais" - ); + let result = + add_or_reactivate_translation_language_with_connection(&connection, "ja", "anglais"); assert!(result.is_err()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8184: - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM translation_languages + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM translation_languages WHERE language_code = 'ja'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8195: fn translation_language_management_retires_without_deleting_history() { let connection = test_connection(); - connection.execute( - "INSERT INTO translations + connection + .execute( + "INSERT INTO translations (work_id, language_code, translation_type, chapter_range) VALUES (1, 'en', 'official', '1-25')", - [], - ).unwrap(); + [], + ) + .unwrap(); retire_translation_language_with_connection(&connection, "en").unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8207: - let stored: (String, String, Option) = connection.query_row( - "SELECT language_code, translation_type, chapter_range + let stored: (String, String, Option) = connection + .query_row( + "SELECT language_code, translation_type, chapter_range FROM translations WHERE work_id = 1", - [], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(stored.0, "en"); assert_eq!(stored.1, "official"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8216: assert_eq!(stored.2.as_deref(), Some("1-25")); let entries = list_translation_languages_with_connection(&connection).unwrap(); - assert!(!entries.iter().find(|entry| entry.key == "en").unwrap().active); + assert!( + !entries + .iter() + .find(|entry| entry.key == "en") + .unwrap() + .active + ); let rejected = connection.execute( "INSERT INTO translations Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8232: fn translation_language_management_reactivates_without_overwriting_settings() { let connection = test_connection(); - connection.execute( - "UPDATE translation_settings + connection + .execute( + "UPDATE translation_settings SET is_tracked = 1, allow_type = 0, allow_chapter_range = 0 WHERE language_code = 'en'", - [], - ).unwrap(); + [], + ) + .unwrap(); retire_translation_language_with_connection(&connection, "en").unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8244: - add_or_reactivate_translation_language_with_connection( - &connection, "EN", "Anglais" - ).unwrap(); + add_or_reactivate_translation_language_with_connection(&connection, "EN", "Anglais") + .unwrap(); - let settings: (i64, i64, i64) = connection.query_row( - "SELECT is_tracked, allow_type, allow_chapter_range + let settings: (i64, i64, i64) = connection + .query_row( + "SELECT is_tracked, allow_type, allow_chapter_range FROM translation_settings WHERE language_code = 'en'", - [], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(settings, (1, 0, 0)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8257: let entries = list_translation_languages_with_connection(&connection).unwrap(); - assert!(entries.iter().find(|entry| entry.key == "en").unwrap().active); + assert!( + entries + .iter() + .find(|entry| entry.key == "en") + .unwrap() + .active + ); - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM translation_languages WHERE language_code = 'en'", - [], - |row| row.get(0), - ).unwrap(); + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM translation_languages WHERE language_code = 'en'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 1); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8270: fn create_work_rejects_retired_translation_type_without_creating_work() { let mut connection = test_connection(); - retire_translation_type_with_connection( - &connection, "official" - ).unwrap(); + retire_translation_type_with_connection(&connection, "official").unwrap(); - let before: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let before: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); let input = CreateWorkInput { original: "Œuvre avec type de traduction retiré".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8291: ..Default::default() }; - assert!( - create_work_with_connection(&mut connection, input).is_err() - ); + assert!(create_work_with_connection(&mut connection, input).is_err()); - let after: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let after: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(before, after); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8308: fn translation_type_management_rejects_unknown_retirement() { let connection = test_connection(); - assert!( - retire_translation_type_with_connection( - &connection, "unknown_type" - ).is_err() - ); - assert!( - retire_translation_type_with_connection( - &connection, " " - ).is_err() - ); + assert!(retire_translation_type_with_connection(&connection, "unknown_type").is_err()); + assert!(retire_translation_type_with_connection(&connection, " ").is_err()); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8324: fn link_type_management_adds_custom_type() { let connection = test_connection(); - add_or_reactivate_link_type_with_connection( - &connection, "official_site", "Site officiel" - ).unwrap(); + add_or_reactivate_link_type_with_connection(&connection, "official_site", "Site officiel") + .unwrap(); let entries = list_link_types_with_connection(&connection).unwrap(); - let entry = entries.iter() + let entry = entries + .iter() .find(|entry| entry.key == "official_site") .unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8343: for key in ["", "Official", "bad key", "_bad", "bad.key"] { assert!( - add_or_reactivate_link_type_with_connection( - &connection, key, "Libellé valide" - ).is_err(), + add_or_reactivate_link_type_with_connection(&connection, key, "Libellé valide") + .is_err(), "La clé {key:?} aurait dû être refusée" ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8352: assert!( - add_or_reactivate_link_type_with_connection( - &connection, "valid_key", " " - ).is_err() + add_or_reactivate_link_type_with_connection(&connection, "valid_key", " ").is_err() ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8361: fn link_type_management_rejects_duplicate_label() { let connection = test_connection(); - let result = add_or_reactivate_link_type_with_connection( - &connection, "custom_reading", "Lecture" - ); + let result = + add_or_reactivate_link_type_with_connection(&connection, "custom_reading", "Lecture"); assert!(result.is_err()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8370: - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM link_types WHERE link_type_key = 'custom_reading'", - [], - |row| row.get(0), - ).unwrap(); + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM link_types WHERE link_type_key = 'custom_reading'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8380: fn link_type_management_retires_without_deleting_history() { let connection = test_connection(); - connection.execute( - "INSERT INTO links(work_id, link_type, label, url) + connection + .execute( + "INSERT INTO links(work_id, link_type, label, url) VALUES (1, 'reading', 'Lien historique', 'https://example.org/old')", - [], - ).unwrap(); + [], + ) + .unwrap(); retire_link_type_with_connection(&connection, "reading").unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8391: - let link: (String, String) = connection.query_row( - "SELECT link_type, label FROM links WHERE work_id = 1", - [], - |row| Ok((row.get(0)?, row.get(1)?)), - ).unwrap(); + let link: (String, String) = connection + .query_row( + "SELECT link_type, label FROM links WHERE work_id = 1", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .unwrap(); assert_eq!(link.0, "reading"); assert_eq!(link.1, "Lien historique"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8399: let all = list_link_types_with_connection(&connection).unwrap(); - assert!(!all.iter().find(|entry| entry.key == "reading").unwrap().active); + assert!( + !all.iter() + .find(|entry| entry.key == "reading") + .unwrap() + .active + ); - let active = all.iter() - .filter(|entry| entry.active) - .collect::>(); + let active = all.iter().filter(|entry| entry.active).collect::>(); assert!(!active.iter().any(|entry| entry.key == "reading")); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8413: retire_link_type_with_connection(&connection, "reading").unwrap(); - add_or_reactivate_link_type_with_connection( - &connection, "reading", "Lecture" - ).unwrap(); + add_or_reactivate_link_type_with_connection(&connection, "reading", "Lecture").unwrap(); let entries = list_link_types_with_connection(&connection).unwrap(); - let entry = entries.iter() - .find(|entry| entry.key == "reading") - .unwrap(); + let entry = entries.iter().find(|entry| entry.key == "reading").unwrap(); assert_eq!(entry.label, "Lecture"); assert!(entry.active); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8427: - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM link_types WHERE link_type_key = 'reading'", - [], - |row| row.get(0), - ).unwrap(); + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM link_types WHERE link_type_key = 'reading'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(count, 1); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8440: retire_link_type_with_connection(&connection, "reading").unwrap(); - let before: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let before: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); let input = CreateWorkInput { original: "Œuvre avec type de lien retiré".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8457: ..Default::default() }; - let error = create_work_with_connection(&mut connection, input) - .unwrap_err(); + let error = create_work_with_connection(&mut connection, input).unwrap_err(); assert!(error.contains("n'existe pas ou n'est plus disponible")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8465: - let after: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let after: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(before, after); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8475: fn link_type_management_rejects_unknown_retirement() { let connection = test_connection(); - assert!( - retire_link_type_with_connection(&connection, "unknown_type").is_err() - ); - assert!( - retire_link_type_with_connection(&connection, " ").is_err() - ); + assert!(retire_link_type_with_connection(&connection, "unknown_type").is_err()); + assert!(retire_link_type_with_connection(&connection, " ").is_err()); } - #[test] fn advanced_search_format_respects_editorial_display_rules() { let connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8490: - connection.execute( - "INSERT INTO works ( + connection + .execute( + "INSERT INTO works ( title_original, editorial_form, editorial_subform ) VALUES ('Test E', 'bande_dessinee', 'bd_occidentale')", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8496: - [], - ).unwrap(); + [], + ) + .unwrap(); - let animation_id: i64 = connection.query_row( - "SELECT id FROM works WHERE title_original = 'Test B'", - [], - |row| row.get(0), - ).unwrap(); + let animation_id: i64 = connection + .query_row( + "SELECT id FROM works WHERE title_original = 'Test B'", + [], + |row| row.get(0), + ) + .unwrap(); - let bd_id: i64 = connection.query_row( - "SELECT id FROM works WHERE title_original = 'Test E'", - [], - |row| row.get(0), - ).unwrap(); + let bd_id: i64 = connection + .query_row( + "SELECT id FROM works WHERE title_original = 'Test E'", + [], + |row| row.get(0), + ) + .unwrap(); let search_ids = |field: &str, value: &str| -> Vec { let mut values = Vec::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8513: - let predicate = advanced_search_condition_sql( - &connection, - field, - value, - &mut values, - ).unwrap(); + let predicate = + advanced_search_condition_sql(&connection, field, value, &mut values).unwrap(); let sql = format!("SELECT id FROM works w WHERE {}", predicate); let mut statement = connection.prepare(&sql).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8522: - statement.query_map( - rusqlite::params_from_iter(values.iter()), - |row| row.get::<_, i64>(0), - ).unwrap() - .collect::, _>>() - .unwrap() + statement + .query_map(rusqlite::params_from_iter(values.iter()), |row| { + row.get::<_, i64>(0) + }) + .unwrap() + .collect::, _>>() + .unwrap() }; // L'animation conserve son format principal à l'affichage. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8535: ); // Son sous-format ne doit pas être confondu avec le format principal. - assert!(search_ids( - "Format éditorial", - "Série d'animation", - ).is_empty()); + assert!(search_ids("Format éditorial", "Série d'animation",).is_empty()); // Le sous-format reste recherchable dans son propre critère. assert_eq!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8552: vec![bd_id], ); - assert!(search_ids( - "Format éditorial", - "Bande dessinée", - ).is_empty()); + assert!(search_ids("Format éditorial", "Bande dessinée",).is_empty()); } - #[test] fn advanced_search_condition_sql_covers_related_catalogues_and_fields() { let connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8565: - connection.execute_batch( - "INSERT INTO works (title_original, editorial_form) + connection + .execute_batch( + "INSERT INTO works (title_original, editorial_form) VALUES ('Test Ero', 'ero_manga'); UPDATE works Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8640: INSERT INTO work_sources (work_id, source_id) SELECT w.id, s.id FROM works w, sources s WHERE w.title_original = 'Test A' - AND s.name = 'Source Recherche SQL';" - ).unwrap(); + AND s.name = 'Source Recherche SQL';", + ) + .unwrap(); - let work_a: i64 = connection.query_row( - "SELECT id FROM works WHERE title_original = 'Test A'", - [], - |row| row.get(0), - ).unwrap(); + let work_a: i64 = connection + .query_row( + "SELECT id FROM works WHERE title_original = 'Test A'", + [], + |row| row.get(0), + ) + .unwrap(); - let work_ero: i64 = connection.query_row( - "SELECT id FROM works WHERE title_original = 'Test Ero'", - [], - |row| row.get(0), - ).unwrap(); + let work_ero: i64 = connection + .query_row( + "SELECT id FROM works WHERE title_original = 'Test Ero'", + [], + |row| row.get(0), + ) + .unwrap(); let search_ids = |field: &str, value: &str| -> Vec { let mut values = Vec::new(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8660: - let predicate = advanced_search_condition_sql( - &connection, field, value, &mut values, - ).unwrap(); + let predicate = + advanced_search_condition_sql(&connection, field, value, &mut values).unwrap(); let sql = format!("SELECT id FROM works w WHERE {}", predicate); let mut statement = connection.prepare(&sql).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8666: - statement.query_map( - rusqlite::params_from_iter(values.iter()), - |row| row.get::<_, i64>(0), - ).unwrap() - .collect::, _>>() - .unwrap() + statement + .query_map(rusqlite::params_from_iter(values.iter()), |row| { + row.get::<_, i64>(0) + }) + .unwrap() + .collect::, _>>() + .unwrap() }; // Champs textuels et personnes. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8722: assert_eq!(search_ids(field, value), vec![work_a], "{field}"); } - assert!( - search_ids("Auteur", "Auteur inexistant").is_empty() - ); + assert!(search_ids("Auteur", "Auteur inexistant").is_empty()); } fn test_connection() -> Connection { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8731: let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch("PRAGMA foreign_keys = ON;").unwrap(); + connection + .execute_batch("PRAGMA foreign_keys = ON;") + .unwrap(); initialize_database(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8736: - connection.execute( - "INSERT INTO works ( + connection + .execute( + "INSERT INTO works ( title_original, editorial_form, editorial_subform ) VALUES Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8742: ('Test B', 'animation', 'serie_animation'), ('Test C', 'doujinshi', NULL), ('Test D', 'light_novel', NULL)", - [], - ).unwrap(); + [], + ) + .unwrap(); // Le jeu de test démarre avec un conteneur principal par œuvre. - connection.execute( - "INSERT INTO work_units (work_id, parent_unit_id, unit_type, label, sort_order) + connection + .execute( + "INSERT INTO work_units (work_id, parent_unit_id, unit_type, label, sort_order) SELECT id, NULL, 'work', 'Œuvre', 0 FROM works", - [], - ).unwrap(); + [], + ) + .unwrap(); connection } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8757: fn unit_count(connection: &Connection) -> i64 { - connection.query_row( - "SELECT COUNT(*) FROM work_units WHERE unit_type != 'work'", - [], - |row| row.get(0), - ).unwrap() + connection + .query_row( + "SELECT COUNT(*) FROM work_units WHERE unit_type != 'work'", + [], + |row| row.get(0), + ) + .unwrap() } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8768: let connection = test_connection(); let work_id = 1_i64; - let main_unit_id: i64 = connection.query_row( - "SELECT id FROM work_units + let main_unit_id: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [work_id], - |row| row.get(0), - ).unwrap(); + [work_id], + |row| row.get(0), + ) + .unwrap(); let auxiliary_unit_id = create_work_unit_with_connection( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8782: "volume".to_string(), "Tome de test".to_string(), 1, - ).unwrap(); + ) + .unwrap(); // Le conteneur principal et une unité auxiliaire active sont autorisés. assert_eq!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8789: - validate_file_association_unit( - &connection, work_id, Some(main_unit_id) - ).unwrap(), + validate_file_association_unit(&connection, work_id, Some(main_unit_id)).unwrap(), main_unit_id ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8795: assert_eq!( - validate_file_association_unit( - &connection, work_id, Some(auxiliary_unit_id) - ).unwrap(), + validate_file_association_unit(&connection, work_id, Some(auxiliary_unit_id)).unwrap(), auxiliary_unit_id ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8802: // Une association directe sans unité est désormais interdite. - let missing_unit_error = validate_file_association_unit( - &connection, work_id, None - ).unwrap_err(); + let missing_unit_error = + validate_file_association_unit(&connection, work_id, None).unwrap_err(); assert!(missing_unit_error.contains("doit être rattachée")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8809: // Une unité appartenant à une autre œuvre est interdite. - let foreign_unit_id: i64 = connection.query_row( - "SELECT id FROM work_units + let foreign_unit_id: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = 2 AND unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert!( - validate_file_association_unit( - &connection, work_id, Some(foreign_unit_id) - ).is_err() + validate_file_association_unit(&connection, work_id, Some(foreign_unit_id)).is_err() ); // Une unité retirée ne peut plus recevoir de nouvelles associations. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8824: - set_work_unit_retired_with_connection( - &connection, - work_id, - auxiliary_unit_id, - true, - ).unwrap(); + set_work_unit_retired_with_connection(&connection, work_id, auxiliary_unit_id, true) + .unwrap(); - let retired_error = validate_file_association_unit( - &connection, work_id, Some(auxiliary_unit_id) - ).unwrap_err(); + let retired_error = + validate_file_association_unit(&connection, work_id, Some(auxiliary_unit_id)) + .unwrap_err(); assert!(retired_error.contains("unité est retirée")); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8869: .unwrap(); // Retirer le parent ne doit ni supprimer ni détacher son enfant. - set_work_unit_retired_with_connection( - &connection, 4, parent_id, true, - ) - .unwrap(); + set_work_unit_retired_with_connection(&connection, 4, parent_id, true).unwrap(); // Répéter la même opération doit rester accepté. - set_work_unit_retired_with_connection( - &connection, 4, parent_id, true, - ) - .unwrap(); + set_work_unit_retired_with_connection(&connection, 4, parent_id, true).unwrap(); let parent_retired: bool = connection .query_row( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8901: assert_eq!(child_state, (Some(parent_id), false)); // Une unité retirée ne peut plus accueillir de nouvel enfant. - assert!( - create_work_unit_with_connection( - &connection, - 4, - Some(parent_id), - "chapter".into(), - "Enfant interdit".into(), - 2, - ) - .is_err() - ); + assert!(create_work_unit_with_connection( + &connection, + 4, + Some(parent_id), + "chapter".into(), + "Enfant interdit".into(), + 2, + ) + .is_err()); // Le conteneur principal ne peut pas être retiré. - assert!( - set_work_unit_retired_with_connection( - &connection, 4, main_id, true, - ) - .is_err() - ); + assert!(set_work_unit_retired_with_connection(&connection, 4, main_id, true,).is_err()); let main_retired: bool = connection .query_row( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8933: // Le retrait collectif ne touche que les unités ordinaires. assert_eq!( - set_all_work_units_retired_with_connection( - &connection, 4, true, - ) - .unwrap(), + set_all_work_units_retired_with_connection(&connection, 4, true,).unwrap(), 1 ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:8943: // La réactivation collective réactive les deux unités. assert_eq!( - set_all_work_units_retired_with_connection( - &connection, 4, false, - ) - .unwrap(), + set_all_work_units_retired_with_connection(&connection, 4, false,).unwrap(), 2 ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9002: let original_document = FileAssociationsDocument { version: 1, next_id: 1, - associations: vec![ - download_test_association( - 1, - work_id, - Some(unit_id), - &source, - ), - ], + associations: vec![download_test_association( + 1, + work_id, + Some(unit_id), + &source, + )], }; - write_file_associations( - &associations.path, - &original_document, - ) - .unwrap(); + write_file_associations(&associations.path, &original_document).unwrap(); // Le retrait ne doit pas modifier l'association JSON. { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9023: let connection = database.connection.lock().unwrap(); - set_work_unit_retired_with_connection( - &connection, - work_id, - unit_id, - true, - ) - .unwrap(); + set_work_unit_retired_with_connection(&connection, work_id, unit_id, true).unwrap(); } - let after_retirement = - read_file_associations(&associations.path).unwrap(); + let after_retirement = read_file_associations(&associations.path).unwrap(); assert_eq!(after_retirement.version, 1); assert_eq!(after_retirement.next_id, 1); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9038: assert_eq!(after_retirement.associations.len(), 1); assert_eq!(after_retirement.associations[0].id, 1); assert_eq!(after_retirement.associations[0].work_id, work_id); + assert_eq!(after_retirement.associations[0].unit_id, Some(unit_id),); assert_eq!( - after_retirement.associations[0].unit_id, - Some(unit_id), - ); - assert_eq!( after_retirement.associations[0].file, source.to_string_lossy(), ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9050: // La réactivation ne doit pas davantage modifier l'association. { let connection = database.connection.lock().unwrap(); - set_work_unit_retired_with_connection( - &connection, - work_id, - unit_id, - false, - ) - .unwrap(); + set_work_unit_retired_with_connection(&connection, work_id, unit_id, false).unwrap(); } - let after_reactivation = - read_file_associations(&associations.path).unwrap(); + let after_reactivation = read_file_associations(&associations.path).unwrap(); assert_eq!(after_reactivation.version, 1); assert_eq!(after_reactivation.next_id, 1); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9067: assert_eq!(after_reactivation.associations.len(), 1); assert_eq!(after_reactivation.associations[0].id, 1); assert_eq!(after_reactivation.associations[0].work_id, work_id); + assert_eq!(after_reactivation.associations[0].unit_id, Some(unit_id),); assert_eq!( - after_reactivation.associations[0].unit_id, - Some(unit_id), - ); - assert_eq!( after_reactivation.associations[0].file, source.to_string_lossy(), ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9092: // Création d'un volume. let volume_id = create_work_unit_with_connection( - &connection, 1, None, - "volume".into(), " Volume 1 ".into(), 1, - ).unwrap(); + &connection, + 1, + None, + "volume".into(), + " Volume 1 ".into(), + 1, + ) + .unwrap(); // Vérification du nettoyage du libellé. - let volume_label: String = connection.query_row( - "SELECT label FROM work_units WHERE id = ?1", - [volume_id], - |row| row.get(0), - ).unwrap(); + let volume_label: String = connection + .query_row( + "SELECT label FROM work_units WHERE id = ?1", + [volume_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(volume_label, "Volume 1"); // Le Manga reste organisé en volumes uniquement. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9108: // Le chapitre est testé sur un Light Novel. let novel_volume_id = create_work_unit_with_connection( - &connection, 4, None, - "volume".into(), "Volume 1".into(), 1, - ).unwrap(); + &connection, + 4, + None, + "volume".into(), + "Volume 1".into(), + 1, + ) + .unwrap(); let chapter_id = create_work_unit_with_connection( - &connection, 4, Some(novel_volume_id), - "chapter".into(), "Chapitre 1".into(), 1, - ).unwrap(); + &connection, + 4, + Some(novel_volume_id), + "chapter".into(), + "Chapitre 1".into(), + 1, + ) + .unwrap(); // Saison et épisode rattaché à cette saison. let season_id = create_work_unit_with_connection( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9121: - &connection, 2, None, - "season".into(), "Saison 1".into(), 1, - ).unwrap(); + &connection, + 2, + None, + "season".into(), + "Saison 1".into(), + 1, + ) + .unwrap(); let episode_id = create_work_unit_with_connection( - &connection, 2, Some(season_id), - "episode".into(), "Épisode 1".into(), 1, - ).unwrap(); + &connection, + 2, + Some(season_id), + "episode".into(), + "Épisode 1".into(), + 1, + ) + .unwrap(); // Une unité autonome item est autorisée pour une œuvre Doujinshi. let item_id = create_work_unit_with_connection( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9132: - &connection, 3, None, - "item".into(), "Doujinshi 1".into(), 1, - ).unwrap(); + &connection, + 3, + None, + "item".into(), + "Doujinshi 1".into(), + 1, + ) + .unwrap(); - let item_type: String = connection.query_row( - "SELECT unit_type FROM work_units WHERE id = ?1", - [item_id], - |row| row.get(0), - ).unwrap(); + let item_type: String = connection + .query_row( + "SELECT unit_type FROM work_units WHERE id = ?1", + [item_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(item_type, "item"); assert_eq!(unit_count(&connection), 6); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9144: // Vérification des liens parent-enfant. - let chapter_parent: Option = connection.query_row( - "SELECT parent_unit_id FROM work_units WHERE id = ?1", - [chapter_id], - |row| row.get(0), - ).unwrap(); + let chapter_parent: Option = connection + .query_row( + "SELECT parent_unit_id FROM work_units WHERE id = ?1", + [chapter_id], + |row| row.get(0), + ) + .unwrap(); - let episode_parent: Option = connection.query_row( - "SELECT parent_unit_id FROM work_units WHERE id = ?1", - [episode_id], - |row| row.get(0), - ).unwrap(); + let episode_parent: Option = connection + .query_row( + "SELECT parent_unit_id FROM work_units WHERE id = ?1", + [episode_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(chapter_parent, Some(novel_volume_id)); assert_eq!(episode_parent, Some(season_id)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9160: // Un parent appartenant à une autre œuvre doit être refusé. assert!(create_work_unit_with_connection( - &connection, 2, Some(volume_id), - "chapter".into(), "Interdit".into(), 2, - ).is_err()); + &connection, + 2, + Some(volume_id), + "chapter".into(), + "Interdit".into(), + 2, + ) + .is_err()); assert_eq!(unit_count(&connection), 6); // Un type invalide doit être refusé. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9169: assert!(create_work_unit_with_connection( - &connection, 1, None, - "invalide".into(), "Test".into(), 2, - ).is_err()); + &connection, + 1, + None, + "invalide".into(), + "Test".into(), + 2, + ) + .is_err()); assert_eq!(unit_count(&connection), 6); // Un libellé vide doit être refusé. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9176: assert!(create_work_unit_with_connection( - &connection, 1, None, - "volume".into(), " ".into(), 2, - ).is_err()); + &connection, + 1, + None, + "volume".into(), + " ".into(), + 2, + ) + .is_err()); assert_eq!(unit_count(&connection), 6); // Une œuvre inexistante doit être refusée. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9183: assert!(create_work_unit_with_connection( - &connection, 999, None, - "volume".into(), "Test".into(), 2, - ).is_err()); + &connection, + 999, + None, + "volume".into(), + "Test".into(), + 2, + ) + .is_err()); assert_eq!(unit_count(&connection), 6); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9211: let connection = test_connection(); // La règle est retirée uniquement dans cette base en mémoire. - connection.execute( - "DELETE FROM unit_root_types + connection + .execute( + "DELETE FROM unit_root_types WHERE form_key = 'light_novel' AND unit_type = 'volume'", - [], - ).unwrap(); + [], + ) + .unwrap(); let result = create_work_unit_with_connection( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9244: "item".into(), "Élément parent".into(), 1, - ).unwrap(); + ) + .unwrap(); let result = create_work_unit_with_connection( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9264: let connection = test_connection(); // Désactivation temporaire dans la seule base en mémoire. - connection.execute( - "UPDATE unit_types + connection + .execute( + "UPDATE unit_types SET is_available = 0 WHERE unit_type = 'volume'", - [], - ).unwrap(); + [], + ) + .unwrap(); let result = create_work_unit_with_connection( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9287: #[test] fn migration_failure_rolls_back_and_reenables_foreign_keys() { let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch("PRAGMA foreign_keys = ON;").unwrap(); + connection + .execute_batch("PRAGMA foreign_keys = ON;") + .unwrap(); let result = execute_migration_with_foreign_keys_disabled( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9306: .unwrap(); assert_eq!(foreign_keys, 1); - let table_exists: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let table_exists: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = 'migration_test_failure'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(table_exists, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9319: #[test] fn migration_with_open_transaction_is_rolled_back() { let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch("PRAGMA foreign_keys = ON;").unwrap(); + connection + .execute_batch("PRAGMA foreign_keys = ON;") + .unwrap(); let result = execute_migration_with_foreign_keys_disabled( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9336: .unwrap(); assert_eq!(foreign_keys, 1); - let table_exists: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let table_exists: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = 'migration_test_open'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(table_exists, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9349: #[test] fn successful_migration_commits_and_reenables_foreign_keys() { let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch("PRAGMA foreign_keys = ON;").unwrap(); + connection + .execute_batch("PRAGMA foreign_keys = ON;") + .unwrap(); execute_migration_with_foreign_keys_disabled( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9358: INSERT INTO migration_test_success VALUES (42); COMMIT;", "Test migration réussie", - ).unwrap(); + ) + .unwrap(); assert!(connection.is_autocommit()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9367: .unwrap(); assert_eq!(foreign_keys, 1); - let value: i64 = connection.query_row( - "SELECT id FROM migration_test_success", - [], - |row| row.get(0), - ).unwrap(); + let value: i64 = connection + .query_row("SELECT id FROM migration_test_success", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(value, 42); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9378: - #[test] fn historical_v1_database_migrates_to_v23_without_data_loss() { // Base exclusivement en mémoire, construite depuis le véritable Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9383: // schéma v1 extrait de la sauvegarde historique. let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch("PRAGMA foreign_keys = ON;").unwrap(); connection + .execute_batch("PRAGMA foreign_keys = ON;") + .unwrap(); + connection .execute_batch(include_str!("../tests/fixtures/schema_v1.sql")) .unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9390: // Deux œuvres historiques : une œuvre originale et son adaptation. - connection.execute( - "INSERT INTO works ( + connection + .execute( + "INSERT INTO works ( id, title_original, romanized, title_english, title_french, editorial_form, author, illustrator, publisher_type, publisher_name, start_date, volume_count, chapter_count, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9404: 'Vérifiée', '2020-01-02T10:00:00Z', '2020-02-03T11:00:00Z' )", - [], - ).unwrap(); + [], + ) + .unwrap(); - connection.execute( - "INSERT INTO works ( + connection + .execute( + "INSERT INTO works ( id, title_original, romanized, title_english, title_french, editorial_form, author, illustrator, publisher_type, publisher_name, start_date, volume_count, chapter_count, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9424: 'Œuvre source', 'Manga', 'Non vérifiée', '2021-03-05T12:00:00Z', '2021-04-06T13:00:00Z' )", - [], - ).unwrap(); + [], + ) + .unwrap(); // Données liées aux œuvres dans les tables historiques. - connection.execute_batch( - "INSERT INTO genres (id, name) VALUES (10, 'Fantastique'); + connection + .execute_batch( + "INSERT INTO genres (id, name) VALUES (10, 'Fantastique'); INSERT INTO demographics (id, name) VALUES (20, 'Seinen'); INSERT INTO tags (id, name) VALUES (30, 'À relire'); INSERT INTO sources (id, name, url, note) Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9457: 70, 2, '2021-05-01T10:00:00Z', 'title_french', 'Ancien titre', 'Adaptation française', 'Historique à conserver' - );" - ).unwrap(); + );", + ) + .unwrap(); // Vérification de la situation initiale. let initial_version: i64 = connection Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9482: .unwrap(); assert_eq!(version, 24); - let search_families: i64 = connection.query_row( - "SELECT COUNT(*) FROM advanced_search_families", - [], - |row| row.get(0), - ).unwrap(); + let search_families: i64 = connection + .query_row("SELECT COUNT(*) FROM advanced_search_families", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(search_families, 29); - let work_nature_columns: i64 = connection.query_row( - "SELECT COUNT(*) FROM pragma_table_info('works') + let work_nature_columns: i64 = connection + .query_row( + "SELECT COUNT(*) FROM pragma_table_info('works') WHERE name = 'work_nature'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(work_nature_columns, 0); // Toutes les unités ordinaires historiques doivent rester actives. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9501: - let retired_legacy_units: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_units + let retired_legacy_units: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_units WHERE unit_type != 'work' AND is_retired != 0", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(retired_legacy_units, 0); // Chaque œuvre historique doit posséder exactement un conteneur principal. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9510: - let main_containers: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_units WHERE unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + let main_containers: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_units WHERE unit_type = 'work'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(main_containers, initial_work_count); - let invalid_main_containers: i64 = connection.query_row( - "SELECT COUNT(*) FROM works w + let invalid_main_containers: i64 = connection + .query_row( + "SELECT COUNT(*) FROM works w WHERE (SELECT COUNT(*) FROM work_units u WHERE u.work_id = w.id AND u.unit_type = 'work') != 1", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(invalid_main_containers, 0); - let legacy_language: Option = connection.query_row( - "SELECT original_language FROM works WHERE id = 1", - [], - |row| row.get(0), - ).unwrap(); + let legacy_language: Option = connection + .query_row( + "SELECT original_language FROM works WHERE id = 1", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(legacy_language, None); let foreign_keys: i64 = connection Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9536: assert_eq!(foreign_keys, 1); // Conservation des champs bibliographiques de l'adaptation. - let adaptation: (String, String, String, String, String) = - connection.query_row( + let adaptation: (String, String, String, String, String) = connection + .query_row( "SELECT title_original, romanized, title_english, title_french, editorial_form FROM works WHERE id = 2", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9544: [], - |row| Ok(( - row.get(0)?, - row.get(1)?, - row.get(2)?, - row.get(3)?, - row.get(4)?, - )), - ).unwrap(); + |row| { + Ok(( + row.get(0)?, + row.get(1)?, + row.get(2)?, + row.get(3)?, + row.get(4)?, + )) + }, + ) + .unwrap(); assert_eq!(adaptation.0, "Adaptation"); assert_eq!(adaptation.1, "Adaptation Romanisée"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9558: assert_eq!(adaptation.4, "light_novel"); // Conservation de la relation avec l'œuvre source. - let source_relation: (Option, Option, Option) = - connection.query_row( + let source_relation: (Option, Option, Option) = connection + .query_row( "SELECT source_work_id, source_work_title, source_work_form FROM works WHERE id = 2", [], Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9566: |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + ) + .unwrap(); assert_eq!(source_relation.0, Some(1)); assert_eq!(source_relation.1.as_deref(), Some("Œuvre source")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9571: assert_eq!(source_relation.2.as_deref(), Some("Manga")); // La relation historique doit aussi exister dans la table normalisée. - let normalized_relation: (String, Option, Option, String, String) = - connection.query_row( + let normalized_relation: (String, Option, Option, String, String) = connection + .query_row( "SELECT direction, related_work_id, related_work_uuid, related_work_title, related_work_form FROM work_adaptations Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9579: WHERE work_id = 2", [], - |row| Ok(( - row.get(0)?, - row.get(1)?, - row.get(2)?, - row.get(3)?, - row.get(4)?, - )), - ).unwrap(); + |row| { + Ok(( + row.get(0)?, + row.get(1)?, + row.get(2)?, + row.get(3)?, + row.get(4)?, + )) + }, + ) + .unwrap(); - let source_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = 1", - [], - |row| row.get(0), - ).unwrap(); + let source_uuid: String = connection + .query_row("SELECT portable_uuid FROM works WHERE id = 1", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(normalized_relation.0, "from"); assert_eq!(normalized_relation.1, Some(1)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9600: assert_eq!(normalized_relation.4, "Manga"); // Les nouveaux champs doivent avoir leurs valeurs attendues. - let new_fields: (Option, Option, i64) = - connection.query_row( + let new_fields: (Option, Option, i64) = connection + .query_row( "SELECT legacy_animation_format, episode_count, is_one_shot FROM works WHERE id = 2", [], Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9608: |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + ) + .unwrap(); assert_eq!(new_fields.0, None); assert_eq!(new_fields.1, None); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9623: ("work_history", 1_i64), ] { let sql = format!("SELECT COUNT(*) FROM {table}"); - let count: i64 = connection - .query_row(&sql, [], |row| row.get(0)) - .unwrap(); + let count: i64 = connection.query_row(&sql, [], |row| row.get(0)).unwrap(); assert_eq!(count, expected, "Données perdues dans {table}"); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9632: // Vérification exacte de la traduction historique après toutes les migrations. - let historical_translation: (i64, i64, String, String, String) = - connection.query_row( + let historical_translation: (i64, i64, String, String, String) = connection + .query_row( "SELECT id, work_id, language_code, translation_type, chapter_range FROM translations WHERE id = 60", [], Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9638: - |row| Ok(( - row.get(0)?, - row.get(1)?, - row.get(2)?, - row.get(3)?, - row.get(4)?, - )), - ).unwrap(); + |row| { + Ok(( + row.get(0)?, + row.get(1)?, + row.get(2)?, + row.get(3)?, + row.get(4)?, + )) + }, + ) + .unwrap(); assert_eq!( historical_translation, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9651: ); // Vérification des valeurs des associations, pas seulement des comptes. - let genre: String = connection.query_row( - "SELECT g.name + let genre: String = connection + .query_row( + "SELECT g.name FROM work_genres wg JOIN genres g ON g.id = wg.genre_id WHERE wg.work_id = 2", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9659: - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(genre, "Fantastique"); - let demographic: String = connection.query_row( - "SELECT d.name + let demographic: String = connection + .query_row( + "SELECT d.name FROM work_demographics wd JOIN demographics d ON d.id = wd.demographic_id WHERE wd.work_id = 2", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9669: - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(demographic, "Seinen"); - let tag: String = connection.query_row( - "SELECT t.name + let tag: String = connection + .query_row( + "SELECT t.name FROM work_tags wt JOIN tags t ON t.id = wt.tag_id WHERE wt.work_id = 2", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9679: - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(tag, "À relire"); // Un tag historique doit rester disponible après la migration v12. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9685: - let historical_tag: (String, i64) = connection.query_row( - "SELECT name, is_available FROM tags WHERE id = 30", - [], - |row| Ok((row.get(0)?, row.get(1)?)), - ).unwrap(); + let historical_tag: (String, i64) = connection + .query_row( + "SELECT name, is_available FROM tags WHERE id = 30", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .unwrap(); assert_eq!(historical_tag.0, "À relire"); assert_eq!(historical_tag.1, 1); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9703: ("trigger", "work_units_parent_insert_guard"), ("trigger", "work_units_parent_update_guard"), ] { - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = ?1 AND name = ?2", - [object_type, object_name], - |row| row.get(0), - ).unwrap(); + [object_type, object_name], + |row| row.get(0), + ) + .unwrap(); assert_eq!( count, 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9721: "work_units_type_insert_guard", "work_units_type_update_guard", ] { - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = 'trigger' AND name = ?1", - [trigger_name], - |row| row.get(0), - ).unwrap(); - assert_eq!(count, 0, "Ancien déclencheur encore présent : {trigger_name}"); + [trigger_name], + |row| row.get(0), + ) + .unwrap(); + assert_eq!( + count, 0, + "Ancien déclencheur encore présent : {trigger_name}" + ); } // La protection contre les changements de format incompatibles doit subsister. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9734: - let compatibility_guard_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let compatibility_guard_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = 'trigger' AND name = 'works_unit_compatibility_update_guard'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!( compatibility_guard_count, 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9746: // Une nouvelle œuvre Doujinshi doit accepter une unité autonome item. // editorial_form stocke la clé stable du catalogue, pas son libellé. - connection.execute( - "INSERT INTO works (title_original, editorial_form) + connection + .execute( + "INSERT INTO works (title_original, editorial_form) VALUES ('Doujinshi après migration', 'doujinshi')", - [], - ).unwrap(); + [], + ) + .unwrap(); let doujinshi_id = connection.last_insert_rowid(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9761: "item".into(), "Doujinshi autonome".into(), 1, - ).unwrap(); + ) + .unwrap(); - let item_type: String = connection.query_row( - "SELECT unit_type FROM work_units WHERE id = ?1", - [item_id], - |row| row.get(0), - ).unwrap(); + let item_type: String = connection + .query_row( + "SELECT unit_type FROM work_units WHERE id = ?1", + [item_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(item_type, "item"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9774: // Aucun défaut de clé étrangère ni corruption SQLite. - let foreign_key_errors: i64 = connection.query_row( - "SELECT COUNT(*) FROM pragma_foreign_key_check", - [], - |row| row.get(0), - ).unwrap(); + let foreign_key_errors: i64 = connection + .query_row("SELECT COUNT(*) FROM pragma_foreign_key_check", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(foreign_key_errors, 0); - let integrity: String = connection.query_row( - "PRAGMA integrity_check", - [], - |row| row.get(0), - ).unwrap(); + let integrity: String = connection + .query_row("PRAGMA integrity_check", [], |row| row.get(0)) + .unwrap(); assert_eq!(integrity, "ok"); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9790: - #[test] fn unsupported_database_versions_are_rejected_without_modification() { for unsupported_version in [26_i64, 99_i64] { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9794: let connection = Connection::open_in_memory().unwrap(); - connection.execute_batch( - "CREATE TABLE sentinel ( + connection + .execute_batch( + "CREATE TABLE sentinel ( id INTEGER PRIMARY KEY, value TEXT NOT NULL ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9801: INSERT INTO sentinel (id, value) - VALUES (1, 'donnée à conserver');" - ).unwrap(); + VALUES (1, 'donnée à conserver');", + ) + .unwrap(); - connection.pragma_update(None, "user_version", unsupported_version) + connection + .pragma_update(None, "user_version", unsupported_version) .unwrap(); let error = initialize_database(&connection).unwrap_err(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9809: assert!( - error.contains(&format!("Version SQLite {unsupported_version} non prise en charge")), + error.contains(&format!( + "Version SQLite {unsupported_version} non prise en charge" + )), "Message inattendu pour la version {unsupported_version} : {error}" ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9817: .unwrap(); assert_eq!(final_version, unsupported_version); - let preserved_value: String = connection.query_row( - "SELECT value FROM sentinel WHERE id = 1", - [], - |row| row.get(0), - ).unwrap(); + let preserved_value: String = connection + .query_row("SELECT value FROM sentinel WHERE id = 1", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(preserved_value, "donnée à conserver"); - let schema_created: i64 = connection.query_row( - "SELECT COUNT(*) FROM sqlite_master + let schema_created: i64 = connection + .query_row( + "SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = 'work_units'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(schema_created, 0); assert!(connection.is_autocommit()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9836: } } - // Insère une œuvre de test sans passer par une commande applicative. - fn insert_test_work( - connection: &Connection, - form: &str, - subform: Option<&str>, - ) -> i64 { - let form_key: String = connection.query_row( - "SELECT form_key FROM editorial_forms + fn insert_test_work(connection: &Connection, form: &str, subform: Option<&str>) -> i64 { + let form_key: String = connection + .query_row( + "SELECT form_key FROM editorial_forms WHERE form_key = ?1 OR label = ?1", - [form], - |row| row.get(0), - ).unwrap(); + [form], + |row| row.get(0), + ) + .unwrap(); let subform_key: Option = subform.map(|value| { - connection.query_row( - "SELECT subform_key FROM editorial_subforms + connection + .query_row( + "SELECT subform_key FROM editorial_subforms WHERE subform_key = ?1 OR label = ?1", - [value], - |row| row.get(0), - ).unwrap() + [value], + |row| row.get(0), + ) + .unwrap() }); - connection.execute( - "INSERT INTO works ( + connection + .execute( + "INSERT INTO works ( title_original, editorial_form, editorial_subform ) VALUES (?1, ?2, ?3)", - params![ - format!("Test déclencheur - {form}"), - form_key, - subform_key - ], - ).unwrap(); + params![format!("Test déclencheur - {form}"), form_key, subform_key], + ) + .unwrap(); connection.last_insert_rowid() } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9898: let first_id = insert_test_work(&connection, "Manga", None); let second_id = insert_test_work(&connection, "Light Novel", None); - let first_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [first_id], - |row| row.get(0), - ).unwrap(); + let first_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [first_id], + |row| row.get(0), + ) + .unwrap(); - let second_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [second_id], - |row| row.get(0), - ).unwrap(); + let second_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [second_id], + |row| row.get(0), + ) + .unwrap(); let is_valid_uuid_v4 = |value: &str| { let bytes = value.as_bytes(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9921: && bytes[14] == b'4' && matches!(bytes[19], b'8' | b'9' | b'a' | b'b') && bytes.iter().enumerate().all(|(index, byte)| { - matches!(index, 8 | 13 | 18 | 23) - || byte.is_ascii_hexdigit() + matches!(index, 8 | 13 | 18 | 23) || byte.is_ascii_hexdigit() }) }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9929: - assert!(is_valid_uuid_v4(&first_uuid), "UUID invalide : {first_uuid}"); - assert!(is_valid_uuid_v4(&second_uuid), "UUID invalide : {second_uuid}"); + assert!( + is_valid_uuid_v4(&first_uuid), + "UUID invalide : {first_uuid}" + ); + assert!( + is_valid_uuid_v4(&second_uuid), + "UUID invalide : {second_uuid}" + ); assert_ne!(first_uuid, second_uuid); - let duplicate_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM works WHERE portable_uuid = ?1", - [&first_uuid], - |row| row.get(0), - ).unwrap(); + let duplicate_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM works WHERE portable_uuid = ?1", + [&first_uuid], + |row| row.get(0), + ) + .unwrap(); assert_eq!(duplicate_count, 1); let attempted_change = connection.execute( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9946: "La modification d'un UUID permanent aurait dû être refusée." ); - let preserved_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [first_id], - |row| row.get(0), - ).unwrap(); + let preserved_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [first_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(preserved_uuid, first_uuid); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9966: (first_target_id, "Premier roman", "Light Novel"), (second_target_id, "Second roman", "Web Novel"), ] { - connection.execute( - "INSERT INTO work_adaptations ( + connection + .execute( + "INSERT INTO work_adaptations ( work_id, direction, relation_label_snapshot, related_work_id, related_work_title, related_work_form ) VALUES (?1, 'from', 'Adaptée de', ?2, ?3, ?4)", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:9974: - (owner_id, target_id, title, form), - ).unwrap(); + (owner_id, target_id, title, form), + ) + .unwrap(); } - let relation_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_adaptations + let relation_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_adaptations WHERE work_id = ?1 AND direction = 'from'", - [owner_id], - |row| row.get(0), - ).unwrap(); + [owner_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(relation_count, 2); - let first_target_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [first_target_id], - |row| row.get(0), - ).unwrap(); + let first_target_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [first_target_id], + |row| row.get(0), + ) + .unwrap(); - let stored_uuid: String = connection.query_row( - "SELECT related_work_uuid FROM work_adaptations + let stored_uuid: String = connection + .query_row( + "SELECT related_work_uuid FROM work_adaptations WHERE work_id = ?1 AND related_work_id = ?2", - (owner_id, first_target_id), - |row| row.get(0), - ).unwrap(); + (owner_id, first_target_id), + |row| row.get(0), + ) + .unwrap(); assert_eq!(stored_uuid, first_target_uuid); - let second_target_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [second_target_id], - |row| row.get(0), - ).unwrap(); + let second_target_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [second_target_id], + |row| row.get(0), + ) + .unwrap(); // Réaffecter la relation : l'UUID doit suivre la nouvelle cible. - connection.execute( - "UPDATE work_adaptations + connection + .execute( + "UPDATE work_adaptations SET related_work_id = ?1 WHERE work_id = ?2 AND related_work_title = 'Premier roman'", - (second_target_id, owner_id), - ).unwrap(); + (second_target_id, owner_id), + ) + .unwrap(); - let reassigned_uuid: String = connection.query_row( - "SELECT related_work_uuid FROM work_adaptations + let reassigned_uuid: String = connection + .query_row( + "SELECT related_work_uuid FROM work_adaptations WHERE work_id = ?1 AND related_work_title = 'Premier roman'", - [owner_id], - |row| row.get(0), - ).unwrap(); + [owner_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(reassigned_uuid, second_target_uuid); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10023: // La suppression de la nouvelle cible doit préserver son UUID. - connection.execute( - "DELETE FROM works WHERE id = ?1", - [second_target_id], - ).unwrap(); + connection + .execute("DELETE FROM works WHERE id = ?1", [second_target_id]) + .unwrap(); - let preserved_target: (Option, Option) = - connection.query_row( + let preserved_target: (Option, Option) = connection + .query_row( "SELECT related_work_id, related_work_uuid FROM work_adaptations WHERE work_id = ?1 AND related_work_title = 'Premier roman'", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10034: [owner_id], |row| Ok((row.get(0)?, row.get(1)?)), - ).unwrap(); + ) + .unwrap(); assert_eq!(preserved_target.0, None); - assert_eq!(preserved_target.1.as_deref(), Some(second_target_uuid.as_str())); + assert_eq!( + preserved_target.1.as_deref(), + Some(second_target_uuid.as_str()) + ); - let remaining_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_adaptations WHERE work_id = ?1", - [owner_id], - |row| row.get(0), - ).unwrap(); + let remaining_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_adaptations WHERE work_id = ?1", + [owner_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(remaining_count, 2); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10069: for (form, expected_type) in forms { let work_id = insert_test_work(&connection, form, None); - let unit_id = insert_test_unit( - &connection, - work_id, - None, - expected_type, - "Unité autorisée", - ).unwrap_or_else(|error| { - panic!("La forme {form} devrait accepter {expected_type} : {error}") - }); + let unit_id = + insert_test_unit(&connection, work_id, None, expected_type, "Unité autorisée") + .unwrap_or_else(|error| { + panic!("La forme {form} devrait accepter {expected_type} : {error}") + }); assert!(unit_id > 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10084: // Les deux sous-formes BD restent rattachées à Bande dessinée. for subform in ["bd_occidentale", "bd_inspiration_manga"] { - let work_id = insert_test_work( - &connection, - "Bande dessinée", - Some(subform), - ); + let work_id = insert_test_work(&connection, "Bande dessinée", Some(subform)); - let volume_id = insert_test_unit( - &connection, - work_id, - None, - "volume", - "Volume BD", - ).unwrap_or_else(|error| { - panic!("La sous-forme BD {subform} devrait accepter volume : {error}") - }); + let volume_id = insert_test_unit(&connection, work_id, None, "volume", "Volume BD") + .unwrap_or_else(|error| { + panic!("La sous-forme BD {subform} devrait accepter volume : {error}") + }); assert!(volume_id > 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10135: ("Animation X", animation_x_formats.as_slice()), ] { for &(subform, expected_type, child_type) in formats { - let work_id = insert_test_work( - &connection, - form, - Some(subform), - ); + let work_id = insert_test_work(&connection, form, Some(subform)); let parent_id = insert_test_unit( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10147: None, expected_type, "Unité d'animation autorisée", - ).unwrap_or_else(|error| { + ) + .unwrap_or_else(|error| { panic!("{form} / {subform} devrait accepter {expected_type} : {error}") }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10158: Some(parent_id), child_type, "Épisode autorisé", - ).unwrap_or_else(|error| { + ) + .unwrap_or_else(|error| { panic!("{form} / {subform} devrait accepter {child_type} : {error}") }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10178: for (index, unit_type) in allowed.iter().enumerate() { let label = format!("Unité autorisée {}", index + 1); assert!( - insert_test_unit( - &connection, work, None, unit_type, &label - ).is_ok(), + insert_test_unit(&connection, work, None, unit_type, &label).is_ok(), "Le type {unit_type} devrait être accepté pour Manga." ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10189: for unit_type in forbidden { assert!( - insert_test_unit( - &connection, work, None, unit_type, "Unité interdite" - ).is_err(), + insert_test_unit(&connection, work, None, unit_type, "Unité interdite").is_err(), "Le type {unit_type} devrait être refusé pour Manga." ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10198: - assert!(insert_test_unit( - &connection, work, None, "type_inconnu", "Type inconnu" - ).is_err()); + assert!(insert_test_unit(&connection, work, None, "type_inconnu", "Type inconnu").is_err()); assert_eq!(unit_count(&connection), 3); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10208: let connection = test_connection(); let work_a = insert_test_work(&connection, "Manga", None); - let work_b = insert_test_work( - &connection, - "Animation", - Some("film_animation"), - ); + let work_b = insert_test_work(&connection, "Animation", Some("film_animation")); - let volume_a = insert_test_unit( - &connection, work_a, None, "volume", "Volume A" - ).unwrap(); + let volume_a = insert_test_unit(&connection, work_a, None, "volume", "Volume A").unwrap(); - let volume_b = insert_test_unit( - &connection, work_a, None, "volume", "Volume B" - ).unwrap(); + let volume_b = insert_test_unit(&connection, work_a, None, "volume", "Volume B").unwrap(); - let foreign_unit = insert_test_unit( - &connection, work_b, None, "item", "Unité autre œuvre" - ).unwrap(); + let foreign_unit = + insert_test_unit(&connection, work_b, None, "item", "Unité autre œuvre").unwrap(); - let chapter = insert_test_unit( - &connection, work_a, Some(volume_a), "chapter", "Chapitre A" - ).unwrap(); + let chapter = + insert_test_unit(&connection, work_a, Some(volume_a), "chapter", "Chapitre A").unwrap(); // Le détachement est permis. - connection.execute( - "UPDATE work_units SET parent_unit_id = NULL WHERE id = ?1", - [chapter], - ).unwrap(); + connection + .execute( + "UPDATE work_units SET parent_unit_id = NULL WHERE id = ?1", + [chapter], + ) + .unwrap(); // Le rattachement à un autre volume de la même œuvre est permis. - connection.execute( - "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", - (volume_b, chapter), - ).unwrap(); + connection + .execute( + "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", + (volume_b, chapter), + ) + .unwrap(); // Un parent d'une autre œuvre reste interdit. - assert!(connection.execute( - "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", - (foreign_unit, chapter), - ).is_err()); + assert!(connection + .execute( + "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", + (foreign_unit, chapter), + ) + .is_err()); // Une boucle dans la hiérarchie reste interdite. - assert!(connection.execute( - "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", - (chapter, volume_b), - ).is_err()); + assert!(connection + .execute( + "UPDATE work_units SET parent_unit_id = ?1 WHERE id = ?2", + (chapter, volume_b), + ) + .is_err()); // Déplacer un chapitre en conservant son parent d'une autre œuvre // reste interdit. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10259: - assert!(connection.execute( - "UPDATE work_units SET work_id = ?1 WHERE id = ?2", - (work_b, chapter), - ).is_err()); + assert!(connection + .execute( + "UPDATE work_units SET work_id = ?1 WHERE id = ?2", + (work_b, chapter), + ) + .is_err()); assert_eq!(unit_count(&connection), 4); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10269: let connection = test_connection(); let manga = insert_test_work(&connection, "Manga", None); - let volume = insert_test_unit( - &connection, manga, None, "volume", "Volume Manga" - ).unwrap(); + let volume = insert_test_unit(&connection, manga, None, "volume", "Volume Manga").unwrap(); // Une œuvre avec un volume ne peut pas devenir un Doujinshi, // car cette forme n'autorise que les éléments. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10278: - assert!(connection.execute( - "UPDATE works SET editorial_form = 'doujinshi' WHERE id = ?1", - [manga], - ).is_err()); + assert!(connection + .execute( + "UPDATE works SET editorial_form = 'doujinshi' WHERE id = ?1", + [manga], + ) + .is_err()); - let form: String = connection.query_row( - "SELECT editorial_form FROM works WHERE id = ?1", - [manga], - |row| row.get(0), - ).unwrap(); + let form: String = connection + .query_row( + "SELECT editorial_form FROM works WHERE id = ?1", + [manga], + |row| row.get(0), + ) + .unwrap(); assert_eq!(form, "manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10291: - let animation = insert_test_work( - &connection, "Animation", Some("serie_animation") - ); + let animation = insert_test_work(&connection, "Animation", Some("serie_animation")); - let season = insert_test_unit( - &connection, animation, None, "season", "Saison 1" - ).unwrap(); + let season = insert_test_unit(&connection, animation, None, "season", "Saison 1").unwrap(); - let episode = insert_test_unit( - &connection, animation, Some(season), "episode", "Épisode 1" - ).unwrap(); + let episode = + insert_test_unit(&connection, animation, Some(season), "episode", "Épisode 1").unwrap(); // La sous-forme film ne permet plus la saison existante. - assert!(connection.execute( - "UPDATE works + assert!(connection + .execute( + "UPDATE works SET editorial_subform = 'film_animation' WHERE id = ?1", - [animation], - ).is_err()); + [animation], + ) + .is_err()); - let subform: Option = connection.query_row( - "SELECT editorial_subform FROM works WHERE id = ?1", - [animation], - |row| row.get(0), - ).unwrap(); + let subform: Option = connection + .query_row( + "SELECT editorial_subform FROM works WHERE id = ?1", + [animation], + |row| row.get(0), + ) + .unwrap(); assert_eq!(subform.as_deref(), Some("serie_animation")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10326: let connection = test_connection(); let work = insert_test_work(&connection, "Manga", None); - let volume = insert_test_unit( - &connection, work, None, "volume", "Volume fichiers" - ).unwrap(); + let volume = + insert_test_unit(&connection, work, None, "volume", "Volume fichiers").unwrap(); // Association externe valide. - connection.execute( - "INSERT INTO unit_files + connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path, file_size) VALUES (?1, 'volume-original.pdf', 'linked', '/bibliotheque/externe/volume.pdf', 1200)", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10339: - [volume], - ).unwrap(); + [volume], + ) + .unwrap(); // Copie gérée valide. - connection.execute( - "INSERT INTO unit_files + connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, managed_path, file_size) VALUES (?1, 'volume-copie.pdf', 'managed', 'managed/volume-copie.pdf', 2400)", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10348: - [volume], - ).unwrap(); + [volume], + ) + .unwrap(); // Mode linked sans chemin source. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode) VALUES (?1, 'sans-chemin.pdf', 'linked')", - [volume], - ).is_err()); + [volume], + ) + .is_err()); // Mode linked avec un chemin managed interdit. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path, managed_path) VALUES (?1, 'double-chemin.pdf', 'linked', Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10365: '/source.pdf', 'managed/cop ie.pdf')", - [volume], - ).is_err()); + [volume], + ) + .is_err()); // Mode managed avec un chemin source interdit. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path, managed_path) VALUES (?1, 'mauvais-mode.pdf', 'managed', Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10375: '/source.pdf', 'managed/fichier.pdf')", - [volume], - ).is_err()); + [volume], + ) + .is_err()); // Nom vide interdit. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path) VALUES (?1, ' ', 'linked', '/source.pdf')", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10385: - [volume], - ).is_err()); + [volume], + ) + .is_err()); // Taille négative interdite. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path, file_size) VALUES (?1, 'taille-negative.pdf', 'linked', Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10394: '/source.pdf', -1)", - [volume], - ).is_err()); + [volume], + ) + .is_err()); // Mode inconnu interdit. - assert!(connection.execute( - "INSERT INTO unit_files + assert!(connection + .execute( + "INSERT INTO unit_files (unit_id, original_filename, storage_mode, source_path) VALUES (?1, 'mode-inconnu.pdf', 'unknown', '/source.pdf')", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10404: - [volume], - ).is_err()); + [volume], + ) + .is_err()); - let file_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM unit_files WHERE unit_id = ?1", - [volume], - |row| row.get(0), - ).unwrap(); + let file_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM unit_files WHERE unit_id = ?1", + [volume], + |row| row.get(0), + ) + .unwrap(); assert_eq!(file_count, 2); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10415: #[test] fn sql_parent_deletion_behavior_is_explicit() { - let connection = test_connection(); let novel = insert_test_work(&connection, "Light Novel", None); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10422: - let volume = insert_test_unit( - &connection, novel, None, "volume", "Volume parent" - ).unwrap(); + let volume = insert_test_unit(&connection, novel, None, "volume", "Volume parent").unwrap(); let chapter = insert_test_unit( - &connection, novel, Some(volume), "chapter", "Chapitre enfant" - ).unwrap(); + &connection, + novel, + Some(volume), + "chapter", + "Chapitre enfant", + ) + .unwrap(); - connection.execute( - "DELETE FROM work_units WHERE id = ?1", - [volume], - ).unwrap(); + connection + .execute("DELETE FROM work_units WHERE id = ?1", [volume]) + .unwrap(); - let chapter_parent: Option = connection.query_row( - "SELECT parent_unit_id FROM work_units WHERE id = ?1", - [chapter], - |row| row.get(0), - ).unwrap(); + let chapter_parent: Option = connection + .query_row( + "SELECT parent_unit_id FROM work_units WHERE id = ?1", + [chapter], + |row| row.get(0), + ) + .unwrap(); assert_eq!(chapter_parent, None); - let season_work = insert_test_work( - &connection, "Animation", Some("Série d'animation") - ); - let season = insert_test_unit( - &connection, season_work, None, "season", "Saison parent" - ).unwrap(); + let season_work = insert_test_work(&connection, "Animation", Some("Série d'animation")); + let season = + insert_test_unit(&connection, season_work, None, "season", "Saison parent").unwrap(); let episode = insert_test_unit( - &connection, season_work, Some(season), "episode", "Épisode enfant" - ).unwrap(); + &connection, + season_work, + Some(season), + "episode", + "Épisode enfant", + ) + .unwrap(); - connection.execute( - "DELETE FROM work_units WHERE id = ?1", - [season], - ).unwrap(); + connection + .execute("DELETE FROM work_units WHERE id = ?1", [season]) + .unwrap(); - let episode_parent: Option = connection.query_row( - "SELECT parent_unit_id FROM work_units WHERE id = ?1", - [episode], - |row| row.get(0), - ).unwrap(); + let episode_parent: Option = connection + .query_row( + "SELECT parent_unit_id FROM work_units WHERE id = ?1", + [episode], + |row| row.get(0), + ) + .unwrap(); assert_eq!(episode_parent, None); assert_eq!(unit_count(&connection), 2); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10511: ); } - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let count: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); // Quatre œuvres de la fixture + treize formes + deux sous-formes BD. assert_eq!(count, 19); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10522: - let main_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_units WHERE unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + let main_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_units WHERE unit_type = 'work'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(main_count, count); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10531: - let auxiliary_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_units WHERE unit_type != 'work'", - [], - |row| row.get(0), - ).unwrap(); + let auxiliary_count: i64 = connection + .query_row( + "SELECT COUNT(*) FROM work_units WHERE unit_type != 'work'", + [], + |row| row.get(0), + ) + .unwrap(); assert_eq!(auxiliary_count, 0); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10618: ]; for (legacy_name, expected_form, expected_subform) in accepted { - let result = normalize_editorial_form(&connection, legacy_name, None) - .unwrap_or_else(|error| { + let result = + normalize_editorial_form(&connection, legacy_name, None).unwrap_or_else(|error| { panic!("L'ancienne appellation {legacy_name} devrait être acceptée : {error}") }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10633: ); } - let explicit_subform = normalize_editorial_form( - &connection, - "bande_dessinee", - Some("bd_occidentale"), - ) - .unwrap(); + let explicit_subform = + normalize_editorial_form(&connection, "bande_dessinee", Some("bd_occidentale")) + .unwrap(); assert_eq!( explicit_subform, - ("bande_dessinee".to_string(), Some("bd_occidentale".to_string())) + ( + "bande_dessinee".to_string(), + Some("bd_occidentale".to_string()) + ) ); let contradictory_subform = normalize_editorial_form( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10651: ); assert!(contradictory_subform.is_err()); - let incompatible_subform = normalize_editorial_form( - &connection, - "Animation", - Some("bd_occidentale"), - ); + let incompatible_subform = + normalize_editorial_form(&connection, "Animation", Some("bd_occidentale")); assert!(incompatible_subform.is_err()); - connection.execute( - "UPDATE editorial_forms SET is_available = 0 WHERE form_key = 'manga'", - [], - ).unwrap(); + connection + .execute( + "UPDATE editorial_forms SET is_available = 0 WHERE form_key = 'manga'", + [], + ) + .unwrap(); let retired_form = normalize_editorial_form(&connection, "Manga", None); assert!(retired_form.is_err()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10668: - assert!( - retired_form.unwrap_err().contains("n'existe pas ou n'est plus disponible") - ); + assert!(retired_form + .unwrap_err() + .contains("n'existe pas ou n'est plus disponible")); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10682: start_date: Some("03/2020".to_string()), ..Default::default() }, - ).unwrap(); + ) + .unwrap(); - let stored: Option = connection.query_row( - "SELECT start_date FROM works WHERE id = ?1", - [id], - |row| row.get(0), - ).unwrap(); + let stored: Option = connection + .query_row("SELECT start_date FROM works WHERE id = ?1", [id], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(stored.as_deref(), Some("03/2020")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10695: for invalid_date in [ - "00/2020", "13/2020", "3/2020", - "03-2020", "03/20ab", "2020-03" + "00/2020", "13/2020", "3/2020", "03-2020", "03/20ab", "2020-03", ] { let result = create_work_with_connection( &mut connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10712: ); } - let count: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let count: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(count, 5); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10734: let id = create_work_with_connection(&mut connection, input).unwrap(); - let legacy_format: Option = connection.query_row( - "SELECT legacy_animation_format FROM works WHERE id = ?1", - [id], - |row| row.get(0), - ).unwrap(); + let legacy_format: Option = connection + .query_row( + "SELECT legacy_animation_format FROM works WHERE id = ?1", + [id], + |row| row.get(0), + ) + .unwrap(); assert_eq!( legacy_format, None, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10751: fn create_work_saves_associations_and_rolls_back_invalid_adaptation() { let mut connection = test_connection(); - connection.execute( - "INSERT OR IGNORE INTO genres(name) VALUES ('Fantastique')", - [], - ).unwrap(); + connection + .execute( + "INSERT OR IGNORE INTO genres(name) VALUES ('Fantastique')", + [], + ) + .unwrap(); - connection.execute( - "INSERT OR IGNORE INTO demographics(name) VALUES ('Seinen')", - [], - ).unwrap(); + connection + .execute( + "INSERT OR IGNORE INTO demographics(name) VALUES ('Seinen')", + [], + ) + .unwrap(); - connection.execute( - "INSERT OR IGNORE INTO tags(name) VALUES ('À relire')", - [], - ).unwrap(); + connection + .execute("INSERT OR IGNORE INTO tags(name) VALUES ('À relire')", []) + .unwrap(); let input = CreateWorkInput { original: "Nouvelle œuvre".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10799: let id = create_work_with_connection(&mut connection, input).unwrap(); - let association_count: i64 = connection.query_row( - "SELECT + let association_count: i64 = connection + .query_row( + "SELECT (SELECT COUNT(*) FROM work_genres WHERE work_id = ?1) + (SELECT COUNT(*) FROM work_demographics WHERE work_id = ?1) + (SELECT COUNT(*) FROM work_tags WHERE work_id = ?1) + Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10807: (SELECT COUNT(*) FROM translations WHERE work_id = ?1) + (SELECT COUNT(*) FROM links WHERE work_id = ?1) + (SELECT COUNT(*) FROM work_sources WHERE work_id = ?1)", - [id], - |row| row.get(0), - ).unwrap(); + [id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(association_count, 7); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10816: - let ranges: (Option, Option) = connection.query_row( - "SELECT + let ranges: (Option, Option) = connection + .query_row( + "SELECT (SELECT chapter_range FROM translations WHERE work_id = ?1 AND translation_type = 'official'), (SELECT chapter_range FROM translations Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10821: WHERE work_id = ?1 AND translation_type = 'fan')", - [id], - |row| Ok((row.get(0)?, row.get(1)?)), - ).unwrap(); + [id], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .unwrap(); assert_eq!(ranges.0.as_deref(), Some("1-25")); assert_eq!(ranges.1.as_deref(), Some("1-42")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10828: - let before: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let before: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); let invalid = CreateWorkInput { original: "Adaptation sans source".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10845: assert!(create_work_with_connection(&mut connection, invalid).is_err()); - let after: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let after: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(before, after); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10856: - #[test] fn catalog_tag_management_preserves_existing_associations() { let connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10869: "manga" }; - connection.execute( - "INSERT INTO works (title_original, editorial_form) + connection + .execute( + "INSERT INTO works (title_original, editorial_form) VALUES (?1, ?2)", - rusqlite::params![ - format!("Œuvre test des catalogues {catalog}"), - form - ], - ).unwrap(); + rusqlite::params![format!("Œuvre test des catalogues {catalog}"), form], + ) + .unwrap(); let work_id = connection.last_insert_rowid(); let name = format!("Tag test {catalog}"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10883: - add_or_reactivate_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + add_or_reactivate_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let tag_id: i64 = connection.query_row( - &format!("SELECT id FROM {catalog} WHERE name = ?1"), - [&name], - |row| row.get(0), - ).unwrap(); + let tag_id: i64 = connection + .query_row( + &format!("SELECT id FROM {catalog} WHERE name = ?1"), + [&name], + |row| row.get(0), + ) + .unwrap(); - connection.execute( - &format!( - "INSERT INTO {association_table}(work_id, tag_id) + connection + .execute( + &format!( + "INSERT INTO {association_table}(work_id, tag_id) VALUES (?1, ?2)" - ), - rusqlite::params![work_id, tag_id], - ).unwrap(); + ), + rusqlite::params![work_id, tag_id], + ) + .unwrap(); - retire_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + retire_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let association_count: i64 = connection.query_row( - &format!( - "SELECT COUNT(*) FROM {association_table} + let association_count: i64 = connection + .query_row( + &format!( + "SELECT COUNT(*) FROM {association_table} WHERE work_id = ?1 AND tag_id = ?2" - ), - rusqlite::params![work_id, tag_id], - |row| row.get(0), - ).unwrap(); + ), + rusqlite::params![work_id, tag_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(association_count, 1); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10917: - let all = list_catalog_tags_with_connection( - &connection, catalog, true - ).unwrap(); + let all = list_catalog_tags_with_connection(&connection, catalog, true).unwrap(); let retired = all.iter().find(|entry| entry.name == name).unwrap(); assert!(!retired.is_available); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10923: - let available = list_catalog_tags_with_connection( - &connection, catalog, false - ).unwrap(); + let available = list_catalog_tags_with_connection(&connection, catalog, false).unwrap(); assert!(!available.iter().any(|entry| entry.name == name)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10930: - add_or_reactivate_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + add_or_reactivate_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let reactivated = list_catalog_tags_with_connection( - &connection, catalog, false - ).unwrap(); + let reactivated = + list_catalog_tags_with_connection(&connection, catalog, false).unwrap(); assert!(reactivated.iter().any(|entry| entry.name == name)); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:10948: ("demographics", "work_demographics", "demographic_id"), ] { let name = format!("Entrée test {catalog}"); - let work_id: i64 = connection.query_row( - "SELECT id FROM works ORDER BY id LIMIT 1", - [], - |row| row.get(0), - ).unwrap(); + let work_id: i64 = connection + .query_row("SELECT id FROM works ORDER BY id LIMIT 1", [], |row| { + row.get(0) + }) + .unwrap(); - add_or_reactivate_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + add_or_reactivate_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let entry_id: i64 = connection.query_row( - &format!("SELECT id FROM {catalog} WHERE name = ?1"), - [&name], - |row| row.get(0), - ).unwrap(); + let entry_id: i64 = connection + .query_row( + &format!("SELECT id FROM {catalog} WHERE name = ?1"), + [&name], + |row| row.get(0), + ) + .unwrap(); - connection.execute( - &format!( - "INSERT INTO {association_table}(work_id, {id_column}) + connection + .execute( + &format!( + "INSERT INTO {association_table}(work_id, {id_column}) VALUES (?1, ?2)" - ), - rusqlite::params![work_id, entry_id], - ).unwrap(); + ), + rusqlite::params![work_id, entry_id], + ) + .unwrap(); - retire_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + retire_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let association_count: i64 = connection.query_row( - &format!( - "SELECT COUNT(*) FROM {association_table} + let association_count: i64 = connection + .query_row( + &format!( + "SELECT COUNT(*) FROM {association_table} WHERE work_id = ?1 AND {id_column} = ?2" - ), - rusqlite::params![work_id, entry_id], - |row| row.get(0), - ).unwrap(); + ), + rusqlite::params![work_id, entry_id], + |row| row.get(0), + ) + .unwrap(); assert_eq!(association_count, 1); - let all = list_catalog_tags_with_connection( - &connection, catalog, true - ).unwrap(); - assert!(!all.iter().find(|entry| entry.name == name).unwrap().is_available); + let all = list_catalog_tags_with_connection(&connection, catalog, true).unwrap(); + assert!( + !all.iter() + .find(|entry| entry.name == name) + .unwrap() + .is_available + ); - let active = list_catalog_tags_with_connection( - &connection, catalog, false - ).unwrap(); + let active = list_catalog_tags_with_connection(&connection, catalog, false).unwrap(); assert!(!active.iter().any(|entry| entry.name == name)); - add_or_reactivate_catalog_tag_with_connection( - &connection, catalog, &name - ).unwrap(); + add_or_reactivate_catalog_tag_with_connection(&connection, catalog, &name).unwrap(); - let active_again = list_catalog_tags_with_connection( - &connection, catalog, false - ).unwrap(); + let active_again = + list_catalog_tags_with_connection(&connection, catalog, false).unwrap(); assert!(active_again.iter().any(|entry| entry.name == name)); } } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11011: fn create_work_rejects_retired_genres_and_demographics() { let mut connection = test_connection(); - connection.execute( - "INSERT INTO genres(name, is_available) VALUES ('Genre retiré', 0)", - [], - ).unwrap(); - connection.execute( - "INSERT INTO demographics(name, is_available) VALUES ('Démographie retirée', 0)", - [], - ).unwrap(); + connection + .execute( + "INSERT INTO genres(name, is_available) VALUES ('Genre retiré', 0)", + [], + ) + .unwrap(); + connection + .execute( + "INSERT INTO demographics(name, is_available) VALUES ('Démographie retirée', 0)", + [], + ) + .unwrap(); - let before: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", [], |row| row.get(0) - ).unwrap(); + let before: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); let invalid_genre = CreateWorkInput { original: "Test genre retiré".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11040: }; assert!(create_work_with_connection(&mut connection, invalid_demographic).is_err()); - let after: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", [], |row| row.get(0) - ).unwrap(); + let after: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(before, after); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11050: fn catalog_tag_management_rejects_unknown_catalog() { let connection = test_connection(); - assert!(list_catalog_tags_with_connection( - &connection, "unknown_catalog", true - ).is_err()); + assert!(list_catalog_tags_with_connection(&connection, "unknown_catalog", true).is_err()); assert!(add_or_reactivate_catalog_tag_with_connection( - &connection, "unknown_catalog", "Tag" - ).is_err()); + &connection, + "unknown_catalog", + "Tag" + ) + .is_err()); - assert!(retire_catalog_tag_with_connection( - &connection, "unknown_catalog", "Tag" - ).is_err()); + assert!(retire_catalog_tag_with_connection(&connection, "unknown_catalog", "Tag").is_err()); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11068: let connection = test_connection(); assert!(add_or_reactivate_catalog_tag_with_connection( - &connection, "secondary_tags", " " - ).is_err()); + &connection, + "secondary_tags", + " " + ) + .is_err()); - assert!(retire_catalog_tag_with_connection( - &connection, "erotic_tags", " " - ).is_err()); + assert!(retire_catalog_tag_with_connection(&connection, "erotic_tags", " ").is_err()); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11080: fn create_work_rejects_retired_tags_without_creating_work() { let mut connection = test_connection(); - connection.execute( - "INSERT INTO tags(name, is_available) VALUES ('Ancien tag', 0)", - [], - ).unwrap(); + connection + .execute( + "INSERT INTO tags(name, is_available) VALUES ('Ancien tag', 0)", + [], + ) + .unwrap(); - let before: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let before: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); let input = CreateWorkInput { original: "Œuvre avec tag retiré".to_string(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11098: ..Default::default() }; - let error = create_work_with_connection(&mut connection, input) - .unwrap_err(); + let error = create_work_with_connection(&mut connection, input).unwrap_err(); assert!(error.contains("n'existe pas ou n'est plus disponible")); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11106: - let after: i64 = connection.query_row( - "SELECT COUNT(*) FROM works", - [], - |row| row.get(0), - ).unwrap(); + let after: i64 = connection + .query_row("SELECT COUNT(*) FROM works", [], |row| row.get(0)) + .unwrap(); assert_eq!(before, after); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11114: - let retained_tag: (i64, i64) = connection.query_row( - "SELECT COUNT(*), MAX(is_available) FROM tags + let retained_tag: (i64, i64) = connection + .query_row( + "SELECT COUNT(*), MAX(is_available) FROM tags WHERE name = 'Ancien tag'", - [], - |row| Ok((row.get(0)?, row.get(1)?)), - ).unwrap(); + [], + |row| Ok((row.get(0)?, row.get(1)?)), + ) + .unwrap(); assert_eq!(retained_tag, (1, 0)); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11168: }, ]; - let error = validate_work_translations( - &connection, - &exact_duplicate, - ).unwrap_err(); + let error = validate_work_translations(&connection, &exact_duplicate).unwrap_err(); assert!( error.contains("déjà renseignée à l'identique"), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11194: ]; assert!( - validate_work_translations( - &connection, - &normalized_duplicate, - ).is_err(), + validate_work_translations(&connection, &normalized_duplicate,).is_err(), "Les doublons après normalisation doivent être refusés." ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11216: ]; assert!( - validate_work_translations( - &connection, - &empty_duplicate, - ).is_err(), + validate_work_translations(&connection, &empty_duplicate,).is_err(), "Les champs vides et absents doivent être équivalents." ); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11231: let input = CreateWorkInput { original: "Traduction amateur uniquement".to_string(), form: "Manga".to_string(), - translations: vec![ - CreateWorkTranslation { - translation_type: "fan".to_string(), - language_code: "en".to_string(), - chapter_range: Some("1-42".to_string()), - }, - ], + translations: vec![CreateWorkTranslation { + translation_type: "fan".to_string(), + language_code: "en".to_string(), + chapter_range: Some("1-42".to_string()), + }], ..Default::default() }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11244: let id = create_work_with_connection(&mut connection, input).unwrap(); let translations: Vec<(String, Option)> = { - let mut statement = connection.prepare( - "SELECT translation_type, chapter_range + let mut statement = connection + .prepare( + "SELECT translation_type, chapter_range FROM translations WHERE work_id = ?1 - ORDER BY translation_type" - ).unwrap(); + ORDER BY translation_type", + ) + .unwrap(); - statement.query_map([id], |row| { - Ok((row.get(0)?, row.get(1)?)) - }).unwrap().collect::, _>>().unwrap() + statement + .query_map([id], |row| Ok((row.get(0)?, row.get(1)?))) + .unwrap() + .collect::, _>>() + .unwrap() }; assert_eq!( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11262: ); } - #[test] fn list_works_hides_suppressed_works_without_deleting_them() { let connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11269: - let hidden_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = 2", - [], - |row| row.get(0), - ).unwrap(); + let hidden_uuid: String = connection + .query_row("SELECT portable_uuid FROM works WHERE id = 2", [], |row| { + row.get(0) + }) + .unwrap(); // Une déclaration concernant une œuvre absente doit être conservable. - connection.execute( - "INSERT INTO work_suppressions (work_uuid, deleted_at, note) + connection + .execute( + "INSERT INTO work_suppressions (work_uuid, deleted_at, note) VALUES ('00000000-0000-4000-8000-000000000001', NULL, 'Œuvre absente')", - [], - ).unwrap(); + [], + ) + .unwrap(); // L'œuvre 2 est masquée, sans suppression de sa fiche. - connection.execute( - "INSERT INTO work_suppressions (work_uuid, deleted_at, note) + connection + .execute( + "INSERT INTO work_suppressions (work_uuid, deleted_at, note) VALUES (?1, '2026-11-20T08:00:00Z', 'Test de masquage')", - [&hidden_uuid], - ).unwrap(); + [&hidden_uuid], + ) + .unwrap(); let works = list_works_with_connection(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11294: assert_eq!(works.len(), 3); // La fiche masquée et ses données restent intégralement en base. - let stored_count: i64 = connection.query_row( - "SELECT COUNT(*) FROM works WHERE id = 2", - [], - |row| row.get(0), - ).unwrap(); + let stored_count: i64 = connection + .query_row("SELECT COUNT(*) FROM works WHERE id = 2", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(stored_count, 1); - let declarations: i64 = connection.query_row( - "SELECT COUNT(*) FROM work_suppressions", - [], - |row| row.get(0), - ).unwrap(); + let declarations: i64 = connection + .query_row("SELECT COUNT(*) FROM work_suppressions", [], |row| { + row.get(0) + }) + .unwrap(); assert_eq!(declarations, 2); // Le retrait de la déclaration rend l'œuvre visible à nouveau. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11312: - connection.execute( - "DELETE FROM work_suppressions WHERE work_uuid = ?1", - [&hidden_uuid], - ).unwrap(); + connection + .execute( + "DELETE FROM work_suppressions WHERE work_uuid = ?1", + [&hidden_uuid], + ) + .unwrap(); let works = list_works_with_connection(&connection).unwrap(); assert!(works.iter().any(|work| work.id == 2)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11319: assert_eq!(works.len(), 4); } - #[test] fn list_works_counts_primary_units_for_work_sizes() { let connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11328: let manga_id = insert_test_work(&connection, "Manga", None); for index in 1..=6 { insert_test_unit( - &connection, manga_id, None, "volume", + &connection, + manga_id, + None, + "volume", &format!("Volume {index}"), - ).unwrap(); + ) + .unwrap(); } // Manga : le compteur renseigné dans la fiche est prioritaire. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11337: let manga_direct_id = insert_test_work(&connection, "Manga", None); - connection.execute( - "UPDATE works SET volume_count = 9 WHERE id = ?1", - [manga_direct_id], - ).unwrap(); + connection + .execute( + "UPDATE works SET volume_count = 9 WHERE id = ?1", + [manga_direct_id], + ) + .unwrap(); for index in 1..=2 { insert_test_unit( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11345: - &connection, manga_direct_id, None, "volume", + &connection, + manga_direct_id, + None, + "volume", &format!("Volume direct {index}"), - ).unwrap(); + ) + .unwrap(); } // BD occidentale : quatre volumes autonomes. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11351: - let bd_id = insert_test_work( - &connection, "Bande dessinée", Some("bd_occidentale"), - ); + let bd_id = insert_test_work(&connection, "Bande dessinée", Some("bd_occidentale")); for index in 1..=4 { insert_test_unit( - &connection, bd_id, None, "volume", + &connection, + bd_id, + None, + "volume", &format!("Volume BD {index}"), - ).unwrap(); + ) + .unwrap(); } // Light Novel : 51 chapitres rattachés à un volume. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11362: let novel_id = insert_test_work(&connection, "Light Novel", None); - let novel_volume_id = insert_test_unit( - &connection, novel_id, None, "volume", "Volume 1", - ).unwrap(); + let novel_volume_id = + insert_test_unit(&connection, novel_id, None, "volume", "Volume 1").unwrap(); for index in 1..=51 { insert_test_unit( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11369: - &connection, novel_id, Some(novel_volume_id), "chapter", + &connection, + novel_id, + Some(novel_volume_id), + "chapter", &format!("Chapitre {index}"), - ).unwrap(); + ) + .unwrap(); } // Animation : 13 épisodes rattachés à une saison. Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11375: - let anime_id = insert_test_work( - &connection, "Animation", Some("serie_animation"), - ); - let season_id = insert_test_unit( - &connection, anime_id, None, "season", "Saison 1", - ).unwrap(); + let anime_id = insert_test_work(&connection, "Animation", Some("serie_animation")); + let season_id = + insert_test_unit(&connection, anime_id, None, "season", "Saison 1").unwrap(); for index in 1..=13 { insert_test_unit( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11384: - &connection, anime_id, Some(season_id), "episode", + &connection, + anime_id, + Some(season_id), + "episode", &format!("Épisode {index}"), - ).unwrap(); + ) + .unwrap(); } let works = list_works_with_connection(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11390: let count_for = |id: i64| { - works.iter() + works + .iter() .find(|work| work.id == id) .unwrap_or_else(|| panic!("Œuvre {id} absente de list_works")) .size_unit_count Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11396: }; - assert_eq!(count_for(manga_id), Some(6), - "Le manga doit compter ses six volumes"); - assert_eq!(count_for(manga_direct_id), Some(9), - "Le compteur de la fiche doit primer sur les unités"); - assert_eq!(count_for(bd_id), Some(4), - "La BD doit compter ses quatre volumes"); - assert_eq!(count_for(novel_id), Some(51), - "Le roman doit compter ses chapitres, pas son volume"); - assert_eq!(count_for(anime_id), Some(13), - "L'animation doit compter ses épisodes, pas sa saison"); + assert_eq!( + count_for(manga_id), + Some(6), + "Le manga doit compter ses six volumes" + ); + assert_eq!( + count_for(manga_direct_id), + Some(9), + "Le compteur de la fiche doit primer sur les unités" + ); + assert_eq!( + count_for(bd_id), + Some(4), + "La BD doit compter ses quatre volumes" + ); + assert_eq!( + count_for(novel_id), + Some(51), + "Le roman doit compter ses chapitres, pas son volume" + ); + assert_eq!( + count_for(anime_id), + Some(13), + "L'animation doit compter ses épisodes, pas sa saison" + ); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11412: let connection = test_connection(); let rules = list_work_size_rules_with_connection(&connection).unwrap(); - let actual: Vec<_> = rules.iter() - .map(|rule| ( - rule.form_key.as_str(), - rule.subform_key.as_deref(), - rule.counter_kind.as_str(), - rule.fallback_unit_type.as_str(), - rule.short_max, - rule.medium_max, - )) + let actual: Vec<_> = rules + .iter() + .map(|rule| { + ( + rule.form_key.as_str(), + rule.subform_key.as_deref(), + rule.counter_kind.as_str(), + rule.fallback_unit_type.as_str(), + rule.short_max, + rule.medium_max, + ) + }) .collect(); let expected = vec![ Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11427: ("animation", Some("ona"), "episode", "episode", 12, 26), ("animation", Some("ova_oav"), "episode", "episode", 12, 26), - ("animation", Some("serie_animation"), "episode", "episode", 12, 26), + ( + "animation", + Some("serie_animation"), + "episode", + "episode", + 12, + 26, + ), ("animation_x", Some("ona"), "episode", "episode", 12, 26), ("animation_x", Some("ova_oav"), "episode", "episode", 12, 26), - ("animation_x", Some("serie_animation"), "episode", "episode", 12, 26), + ( + "animation_x", + Some("serie_animation"), + "episode", + "episode", + 12, + 26, + ), ("bande_dessinee", None, "volume", "volume", 3, 8), ("ero_manga", None, "volume", "volume", 5, 20), ("light_novel", None, "chapter", "chapter", 50, 150), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11442: ]; assert_eq!(actual.len(), 15, "Le nombre de règles doit être de 15"); - assert_eq!(actual, expected, "Les règles, seuils ou leur ordre ont changé"); + assert_eq!( + actual, expected, + "Les règles, seuils ou leur ordre ont changé" + ); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11482: let id = create_work_with_connection(&mut connection, input).unwrap(); let works = list_works_with_connection(&connection).unwrap(); - let work = works.iter() + let work = works + .iter() .find(|work| work.id == id) .expect("L'œuvre créée doit être présente dans list_works"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11489: assert_eq!(work.translations.len(), 2); - let official = work.translations.iter() + let official = work + .translations + .iter() .find(|translation| translation.translation_type.as_deref() == Some("official")) .expect("La traduction officielle doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11496: assert_eq!(official.language_code, "en"); assert_eq!(official.chapter_range.as_deref(), Some("1-25")); - let fan = work.translations.iter() + let fan = work + .translations + .iter() .find(|translation| translation.translation_type.as_deref() == Some("fan")) .expect("La traduction amateur doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11511: work.links, vec!["Lecture : https://example.invalid/read".to_string()] ); - assert_eq!( - work.sources, - vec!["Source de lecture".to_string()] - ); + assert_eq!(work.sources, vec!["Source de lecture".to_string()]); assert_eq!(work.animation_format, None); assert_eq!(work.episodes, None); assert!(!work.one_shot); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11542: }], ..Default::default() }, - ).unwrap(); + ) + .unwrap(); // C est une adaptation de B. let adaptation_c_id = create_work_with_connection( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11558: }], ..Default::default() }, - ).unwrap(); + ) + .unwrap(); let works = list_works_with_connection(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11565: - let original = works.iter() + let original = works + .iter() .find(|work| work.id == original_id) .expect("L'œuvre originale A doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11569: - let adaptation_b = works.iter() + let adaptation_b = works + .iter() .find(|work| work.id == adaptation_b_id) .expect("L'adaptation B doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11573: - let adaptation_c = works.iter() + let adaptation_c = works + .iter() .find(|work| work.id == adaptation_c_id) .expect("L'adaptation C doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11590: // Vérification des liens « Adaptée en ». assert_eq!(original.adapted_into.len(), 1); assert_eq!(original.adapted_into[0].id, Some(adaptation_b_id)); - assert_eq!( - original.adapted_into[0].title, - "Adaptation B anglaise" - ); + assert_eq!(original.adapted_into[0].title, "Adaptation B anglaise"); assert_eq!(original.adapted_into[0].form.as_deref(), Some("Animation")); assert_eq!(adaptation_b.adapted_into.len(), 1); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11600: assert_eq!(adaptation_b.adapted_into[0].id, Some(adaptation_c_id)); + assert_eq!(adaptation_b.adapted_into[0].title, "Adaptation C anglaise"); assert_eq!( - adaptation_b.adapted_into[0].title, - "Adaptation C anglaise" + adaptation_b.adapted_into[0].form.as_deref(), + Some("Doujinshi") ); - assert_eq!(adaptation_b.adapted_into[0].form.as_deref(), Some("Doujinshi")); assert!(adaptation_c.adapted_from.len() == 1); assert_eq!(adaptation_c.adapted_from[0].title, "Adaptation B anglaise"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11625: }], ..Default::default() }, - ).unwrap(); + ) + .unwrap(); - let snapshot: (Option, String, Option) = connection.query_row( - "SELECT related_work_id, related_work_title, related_work_form + let snapshot: (Option, String, Option) = connection + .query_row( + "SELECT related_work_id, related_work_title, related_work_form FROM work_adaptations WHERE work_id = ?1", - [work_id], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [work_id], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(snapshot.0, None); assert_eq!(snapshot.1, "Roman externe"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11641: // Simuler une relation externe restaurée depuis un export portable. let external_uuid = "123e4567-e89b-42d3-a456-426614174000"; - connection.execute( - "UPDATE work_adaptations + connection + .execute( + "UPDATE work_adaptations SET related_work_uuid = ?1 WHERE work_id = ?2", - (external_uuid, work_id), - ).unwrap(); + (external_uuid, work_id), + ) + .unwrap(); let works = list_works_with_connection(&connection).unwrap(); - let adaptation = works.iter() + let adaptation = works + .iter() .find(|work| work.id == work_id) .expect("La nouvelle œuvre doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11688: ], ..Default::default() }, - ).unwrap(); + ) + .unwrap(); let relations: Vec<(String, Option, String, Option)> = { - let mut statement = connection.prepare( - "SELECT direction, related_work_id, + let mut statement = connection + .prepare( + "SELECT direction, related_work_id, related_work_title, related_work_form FROM work_adaptations WHERE work_id = ?1 Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11699: - ORDER BY direction" - ).unwrap(); + ORDER BY direction", + ) + .unwrap(); - statement.query_map([work_id], |row| { - Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)) - }).unwrap().collect::, _>>().unwrap() + statement + .query_map([work_id], |row| { + Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)) + }) + .unwrap() + .collect::, _>>() + .unwrap() }; assert_eq!(relations.len(), 2); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11708: - let from = relations.iter() + let from = relations + .iter() .find(|relation| relation.0 == "from") .unwrap(); assert_eq!(from.1, Some(existing_id)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11713: assert_eq!(from.2, "Test A"); assert_eq!(from.3.as_deref(), Some("manga")); - let into = relations.iter() + let into = relations + .iter() .find(|relation| relation.0 == "into") .unwrap(); assert_eq!(into.1, None); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11736: let original_id = 1_i64; - let original_before: (String, String, Option) = - connection.query_row( + let original_before: (String, String, Option) = connection + .query_row( "SELECT title_original, editorial_form, title_english FROM works WHERE id = ?1", [original_id], Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11744: |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + ) + .unwrap(); let adaptation_id = create_work_with_connection( &mut connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11757: }], ..Default::default() }, - ).unwrap(); + ) + .unwrap(); - let relation: (String, Option, String, Option) = - connection.query_row( + let relation: (String, Option, String, Option) = connection + .query_row( "SELECT direction, related_work_id, related_work_title, related_work_form FROM work_adaptations Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11767: WHERE work_id = ?1", [adaptation_id], - |row| Ok(( - row.get(0)?, - row.get(1)?, - row.get(2)?, - row.get(3)?, - )), - ).unwrap(); + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)), + ) + .unwrap(); assert_eq!(relation.0, "into"); assert_eq!(relation.1, Some(original_id)); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11780: assert_eq!(relation.3.as_deref(), Some("manga")); // La création de la relation ne doit pas modifier la fiche liée. - let original_after: (String, String, Option) = - connection.query_row( + let original_after: (String, String, Option) = connection + .query_row( "SELECT title_original, editorial_form, title_english FROM works WHERE id = ?1", [original_id], Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11788: |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + ) + .unwrap(); assert_eq!(original_after, original_before); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11793: - let original_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [original_id], - |row| row.get(0), - ).unwrap(); + let original_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [original_id], + |row| row.get(0), + ) + .unwrap(); - let adaptation_uuid: String = connection.query_row( - "SELECT portable_uuid FROM works WHERE id = ?1", - [adaptation_id], - |row| row.get(0), - ).unwrap(); + let adaptation_uuid: String = connection + .query_row( + "SELECT portable_uuid FROM works WHERE id = ?1", + [adaptation_id], + |row| row.get(0), + ) + .unwrap(); // Vérification de la lecture dans les deux fiches. let works = list_works_with_connection(&connection).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11807: - let original = works.iter() + let original = works + .iter() .find(|work| work.id == original_id) .expect("La fiche liée doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11812: - let adaptation = works.iter() + let adaptation = works + .iter() .find(|work| work.id == adaptation_id) .expect("La fiche d'adaptation doit être présente"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11832: ); // Suppression de la fiche liée : le snapshot doit survivre. - connection.execute( - "DELETE FROM works WHERE id = ?1", - [original_id], - ).unwrap(); + connection + .execute("DELETE FROM works WHERE id = ?1", [original_id]) + .unwrap(); - let preserved: (Option, String, Option) = connection.query_row( - "SELECT related_work_id, related_work_title, related_work_form + let preserved: (Option, String, Option) = connection + .query_row( + "SELECT related_work_id, related_work_title, related_work_form FROM work_adaptations WHERE work_id = ?1", - [adaptation_id], - |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), - ).unwrap(); + [adaptation_id], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + .unwrap(); assert_eq!(preserved.0, None); assert_eq!(preserved.1, "Test A"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11850: assert_eq!(preserved.2.as_deref(), Some("manga")); let works_after = list_works_with_connection(&connection).unwrap(); - let adaptation_after = works_after.iter() + let adaptation_after = works_after + .iter() .find(|work| work.id == adaptation_id) .expect("La fiche d'adaptation doit survivre"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11857: assert_eq!(adaptation_after.adapted_into.len(), 1); assert_eq!(adaptation_after.adapted_into[0].id, None); assert_eq!(adaptation_after.adapted_into[0].title, "Test A"); - assert_eq!(adaptation_after.adapted_into[0].form.as_deref(), Some("Manga")); + assert_eq!( + adaptation_after.adapted_into[0].form.as_deref(), + Some("Manga") + ); } - - fn download_test_environment( - label: &str, - ) -> (PathBuf, Database, FileAssociationsState) { + fn download_test_environment(label: &str) -> (PathBuf, Database, FileAssociationsState) { let associations_path = temporary_associations_path(label); let root = associations_path.parent().unwrap().to_path_buf(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11919: ) } - fn create_download_test_source( - root: &Path, - name: &str, - contents: &str, - ) -> PathBuf { + fn create_download_test_source(root: &Path, name: &str, contents: &str) -> PathBuf { let source_dir = root.join("sources"); std::fs::create_dir_all(&source_dir).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11934: #[test] fn download_complete_work_includes_only_main_container_files() { - let (root, database, associations) = - download_test_environment("download-complete-work"); + let (root, database, associations) = download_test_environment("download-complete-work"); let (main_unit_id, auxiliary_unit_id) = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11942: - let main_id: i64 = connection.query_row( - "SELECT id FROM work_units + let main_id: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = 1 AND unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); let auxiliary_id = create_work_unit_with_connection( &connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11954: "volume".into(), "Volume 1".into(), 1, - ).unwrap(); + ) + .unwrap(); (main_id, auxiliary_id) }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11961: - let direct = create_download_test_source( - &root, "direct.pdf", "direct", - ); - let main_file = create_download_test_source( - &root, "principal.pdf", "principal", - ); - let auxiliary_file = create_download_test_source( - &root, "volume.pdf", "volume", - ); + let direct = create_download_test_source(&root, "direct.pdf", "direct"); + let main_file = create_download_test_source(&root, "principal.pdf", "principal"); + let auxiliary_file = create_download_test_source(&root, "volume.pdf", "volume"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:11982: write_file_associations(&associations.path, &document).unwrap(); let json_before = std::fs::read(&associations.path).unwrap(); - let report = run_download_test( - &database, - &associations, - vec![1], - vec![], - false, - None, - ).unwrap(); + let report = + run_download_test(&database, &associations, vec![1], vec![], false, None).unwrap(); let work_dir = associations.downloads_path.join("Test A - Manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12011: #[test] fn download_selected_unit_excludes_direct_and_other_unit_files() { - let (root, database, associations) = - download_test_environment("download-selected-unit"); + let (root, database, associations) = download_test_environment("download-selected-unit"); let (selected_unit, other_unit) = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12019: let first = create_work_unit_with_connection( - &connection, 1, None, - "volume".into(), "Volume 1".into(), 1, - ).unwrap(); + &connection, + 1, + None, + "volume".into(), + "Volume 1".into(), + 1, + ) + .unwrap(); let second = create_work_unit_with_connection( - &connection, 1, None, - "volume".into(), "Volume 2".into(), 2, - ).unwrap(); + &connection, + 1, + None, + "volume".into(), + "Volume 2".into(), + 2, + ) + .unwrap(); (first, second) }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12032: - let direct = create_download_test_source( - &root, "direct.pdf", "direct", - ); - let selected = create_download_test_source( - &root, "selected.pdf", "selected", - ); - let other = create_download_test_source( - &root, "other.pdf", "other", - ); + let direct = create_download_test_source(&root, "direct.pdf", "direct"); + let selected = create_download_test_source(&root, "selected.pdf", "selected"); + let other = create_download_test_source(&root, "other.pdf", "other"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12059: vec![selected_unit], false, None, - ).unwrap(); + ) + .unwrap(); let work_dir = associations.downloads_path.join("Test A - Manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12073: #[test] fn download_deduplicates_same_canonical_file_without_changing_json() { - let (root, database, associations) = - download_test_environment("download-deduplication"); + let (root, database, associations) = download_test_environment("download-deduplication"); let main_unit_id = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12081: - connection.query_row( - "SELECT id FROM work_units + connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [1_i64], - |row| row.get::<_, i64>(0), - ).unwrap() + [1_i64], + |row| row.get::<_, i64>(0), + ) + .unwrap() }; - let source = create_download_test_source( - &root, "shared.pdf", "shared contents", - ); + let source = create_download_test_source(&root, "shared.pdf", "shared contents"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12103: let json_before = std::fs::read(&associations.path).unwrap(); - let report = run_download_test( - &database, - &associations, - vec![1], - vec![], - false, - None, - ).unwrap(); + let report = + run_download_test(&database, &associations, vec![1], vec![], false, None).unwrap(); let json_after = std::fs::read(&associations.path).unwrap(); let work_dir = associations.downloads_path.join("Test A - Manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12128: #[test] fn download_same_source_to_two_colliding_work_names() { - let (root, database, associations) = - download_test_environment("download-work-collisions"); + let (root, database, associations) = download_test_environment("download-work-collisions"); { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12136: - connection.execute( - "INSERT INTO works + connection + .execute( + "INSERT INTO works (title_original, editorial_form, editorial_subform) VALUES ('Test A', 'manga', NULL)", - [], - ).unwrap(); + [], + ) + .unwrap(); - connection.execute( - "INSERT INTO work_units + connection + .execute( + "INSERT INTO work_units (work_id, parent_unit_id, unit_type, label, sort_order) VALUES (5, NULL, 'work', 'Œuvre', 0)", - [], - ).unwrap(); + [], + ) + .unwrap(); } let (first_main_id, second_main_id) = { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12152: let connection = database.connection.lock().unwrap(); - let first: i64 = connection.query_row( - "SELECT id FROM work_units + let first: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = 1 AND unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); - let second: i64 = connection.query_row( - "SELECT id FROM work_units + let second: i64 = connection + .query_row( + "SELECT id FROM work_units WHERE work_id = 5 AND unit_type = 'work'", - [], - |row| row.get(0), - ).unwrap(); + [], + |row| row.get(0), + ) + .unwrap(); (first, second) }; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12170: - let source = create_download_test_source( - &root, "shared.pdf", "shared", - ); + let source = create_download_test_source(&root, "shared.pdf", "shared"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12183: write_file_associations(&associations.path, &document).unwrap(); - let report = run_download_test( - &database, - &associations, - vec![1, 5], - vec![], - false, - None, - ).unwrap(); + let report = + run_download_test(&database, &associations, vec![1, 5], vec![], false, None).unwrap(); let first_dir = associations.downloads_path.join("Test A - Manga [1]"); let second_dir = associations.downloads_path.join("Test A - Manga [5]"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12204: #[test] fn global_download_creates_new_batch_and_never_overwrites_files() { - let (root, database, associations) = - download_test_environment("download-global-batch"); + let (root, database, associations) = download_test_environment("download-global-batch"); let main_unit_id = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12212: - connection.query_row( - "SELECT id FROM work_units + connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [1_i64], - |row| row.get::<_, i64>(0), - ).unwrap() + [1_i64], + |row| row.get::<_, i64>(0), + ) + .unwrap() }; - let source = create_download_test_source( - &root, "document.pdf", "new contents", - ); + let source = create_download_test_source(&root, "document.pdf", "new contents"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12226: next_id: 1, - associations: vec![ - download_test_association(1, 1, Some(main_unit_id), &source), - ], + associations: vec![download_test_association(1, 1, Some(main_unit_id), &source)], }; write_file_associations(&associations.path, &document).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12233: let batch_name = "Bibliotheca - test"; - let existing_dir = associations.downloads_path + let existing_dir = associations + .downloads_path .join(batch_name) .join("Test A - Manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12239: std::fs::create_dir_all(&existing_dir).unwrap(); - std::fs::write( - existing_dir.join("document.pdf"), - "original contents", - ).unwrap(); + std::fs::write(existing_dir.join("document.pdf"), "original contents").unwrap(); let report = run_download_test( &database, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12249: vec![], true, Some(batch_name), - ).unwrap(); + ) + .unwrap(); assert_eq!(report.copied_files, 1); - assert_eq!(report.output_folders.first().map(String::as_str), Some("Bibliotheca - test (2)")); + assert_eq!( + report.output_folders.first().map(String::as_str), + Some("Bibliotheca - test (2)") + ); - let new_file = associations.downloads_path + let new_file = associations + .downloads_path .join("Bibliotheca - test (2)") .join("Test A - Manga") .join("document.pdf"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12265: std::fs::read_to_string(&original_file).unwrap(), "original contents", ); - assert_eq!( - std::fs::read_to_string(&new_file).unwrap(), - "new contents", - ); + assert_eq!(std::fs::read_to_string(&new_file).unwrap(), "new contents",); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12275: #[test] fn download_reports_missing_source_without_failing_operation() { - let (root, database, associations) = - download_test_environment("download-missing-source"); + let (root, database, associations) = download_test_environment("download-missing-source"); let main_unit_id = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12283: - connection.query_row( - "SELECT id FROM work_units + connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [1_i64], - |row| row.get::<_, i64>(0), - ).unwrap() + [1_i64], + |row| row.get::<_, i64>(0), + ) + .unwrap() }; let missing = root.join("sources").join("absent.pdf"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12293: let document = FileAssociationsDocument { version: 1, next_id: 1, - associations: vec![ - download_test_association(1, 1, Some(main_unit_id), &missing), - ], + associations: vec![download_test_association( + 1, + 1, + Some(main_unit_id), + &missing, + )], }; write_file_associations(&associations.path, &document).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12302: - let report = run_download_test( - &database, - &associations, - vec![1], - vec![], - false, - None, - ).unwrap(); + let report = + run_download_test(&database, &associations, vec![1], vec![], false, None).unwrap(); assert_eq!(report.copied_files, 0); assert_eq!(report.missing_files, vec!["absent.pdf".to_string()]); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12316: let _ = std::fs::remove_dir_all(root); } - #[test] fn download_combined_work_and_unit_selection_does_not_duplicate_files() { let (root, database, associations) = Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12324: let main_unit_id = { let connection = database.connection.lock().unwrap(); - connection.query_row( - "SELECT id FROM work_units + connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [1_i64], - |row| row.get::<_, i64>(0), - ).unwrap() + [1_i64], + |row| row.get::<_, i64>(0), + ) + .unwrap() }; let unit_id = { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12341: "volume".into(), "Volume 1".into(), 1, - ).unwrap() + ) + .unwrap() }; - let direct = create_download_test_source( - &root, "direct.pdf", "direct contents", - ); - let unit_file = create_download_test_source( - &root, "volume.pdf", "volume contents", - ); + let direct = create_download_test_source(&root, "direct.pdf", "direct contents"); + let unit_file = create_download_test_source(&root, "volume.pdf", "volume contents"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12369: vec![unit_id], false, None, - ).unwrap(); + ) + .unwrap(); let work_dir = associations.downloads_path.join("Test A - Manga"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12394: #[test] fn download_file_collision_preserves_existing_file_and_adds_suffix() { - let (root, database, associations) = - download_test_environment("download-file-collision"); + let (root, database, associations) = download_test_environment("download-file-collision"); let main_unit_id = { let connection = database.connection.lock().unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12402: - connection.query_row( - "SELECT id FROM work_units + connection + .query_row( + "SELECT id FROM work_units WHERE work_id = ?1 AND unit_type = 'work'", - [1_i64], - |row| row.get::<_, i64>(0), - ).unwrap() + [1_i64], + |row| row.get::<_, i64>(0), + ) + .unwrap() }; - let source = create_download_test_source( - &root, "document.pdf", "new contents", - ); + let source = create_download_test_source(&root, "document.pdf", "new contents"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12416: next_id: 1, - associations: vec![ - download_test_association(1, 1, Some(main_unit_id), &source), - ], + associations: vec![download_test_association(1, 1, Some(main_unit_id), &source)], }; write_file_associations(&associations.path, &document).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12427: let original_file = work_dir.join("document.pdf"); std::fs::write(&original_file, "original contents").unwrap(); - let report = run_download_test( - &database, - &associations, - vec![1], - vec![], - false, - None, - ).unwrap(); + let report = + run_download_test(&database, &associations, vec![1], vec![], false, None).unwrap(); let copied_file = work_dir.join("document (1).pdf"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12454: let _ = std::fs::remove_dir_all(root); } - - #[test] fn remove_all_associations_preserves_other_works_and_source_files() { let (root, database, associations) = Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12470: "volume".into(), "Volume 1".into(), 1, - ).unwrap() + ) + .unwrap() }; - let direct = create_download_test_source( - &root, "direct.pdf", "source directe", - ); - let unit_file = create_download_test_source( - &root, "volume.pdf", "source du volume", - ); - let other_work = create_download_test_source( - &root, "other.pdf", "source autre œuvre", - ); + let direct = create_download_test_source(&root, "direct.pdf", "source directe"); + let unit_file = create_download_test_source(&root, "volume.pdf", "source du volume"); + let other_work = create_download_test_source(&root, "other.pdf", "source autre œuvre"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12495: write_file_associations(&associations.path, &document).unwrap(); - let removed = remove_all_file_associations_internal( - 1, - &database, - &associations, - ).unwrap(); + let removed = remove_all_file_associations_internal(1, &database, &associations).unwrap(); assert_eq!(removed, 2); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12508: assert_eq!(after.associations[0].id, 3); assert_eq!(after.associations[0].work_id, 2); + assert_eq!(std::fs::read_to_string(&direct).unwrap(), "source directe",); assert_eq!( - std::fs::read_to_string(&direct).unwrap(), - "source directe", - ); - assert_eq!( std::fs::read_to_string(&unit_file).unwrap(), "source du volume", ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12538: "volume".into(), "Volume 1".into(), 1, - ).unwrap() + ) + .unwrap() }; - let direct = create_download_test_source( - &root, "direct.pdf", "nouveau contenu direct", - ); - let unit_file = create_download_test_source( - &root, "volume.pdf", "contenu du volume", - ); + let direct = create_download_test_source(&root, "direct.pdf", "nouveau contenu direct"); + let unit_file = create_download_test_source(&root, "volume.pdf", "contenu du volume"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12571: associations.downloads_path.to_string_lossy().into_owned(), &database, &associations, - ).unwrap(); + ) + .unwrap(); assert_eq!(report.copied_files, 2); assert!(report.missing_files.is_empty()); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12614: let (root, database, associations) = download_test_environment("selected-associations-foreign"); - let foreign_source = create_download_test_source( - &root, "foreign.pdf", "source étrangère", - ); + let foreign_source = create_download_test_source(&root, "foreign.pdf", "source étrangère"); let document = FileAssociationsDocument { version: 1, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12623: next_id: 1, - associations: vec![ - download_test_association(1, 2, None, &foreign_source), - ], + associations: vec![download_test_association(1, 2, None, &foreign_source)], }; write_file_associations(&associations.path, &document).unwrap(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12658: let _ = std::fs::remove_dir_all(root); } - fn portable_test_library( label: &str, suppression_path: &str, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12682: std::fs::write( root.join("suppressions/suppressions.json"), suppression_json, - ).unwrap(); + ) + .unwrap(); let mut included = vec!["suppressions"]; let mut excluded = vec![ Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12741: std::fs::write( root.join("manifest.json"), serde_json::to_vec_pretty(&manifest).unwrap(), - ).unwrap(); + ) + .unwrap(); root } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12748: - fn portable_test_update_manifest( root: &std::path::Path, update: impl FnOnce(&mut serde_json::Value), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12753: ) { let path = root.join("manifest.json"); let bytes = std::fs::read(&path).unwrap(); - let mut manifest: serde_json::Value = - serde_json::from_slice(&bytes).unwrap(); + let mut manifest: serde_json::Value = serde_json::from_slice(&bytes).unwrap(); update(&mut manifest); - std::fs::write( - path, - serde_json::to_vec_pretty(&manifest).unwrap(), - ).unwrap(); + std::fs::write(path, serde_json::to_vec_pretty(&manifest).unwrap()).unwrap(); } - fn portable_test_include_fingerprint_category( root: &std::path::Path, category: &str, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12773: portable_test_update_manifest(root, |manifest| { manifest["contents"]["included"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!(category)); manifest["contents"]["excluded"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12780: - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .retain(|value| value.as_str() != Some(category)); manifest["contents"][category] = serde_json::json!({ Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12785: "count": 0 }); - manifest["integrity"][integrity_key] = - serde_json::json!(relative_path); + manifest["integrity"][integrity_key] = serde_json::json!(relative_path); }); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12801: let result = portable_safe_path(&root, "."); - assert!( - result.is_err(), - "Le chemin « . » doit être refusé." - ); + assert!(result.is_err(), "Le chemin « . » doit être refusé."); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12820: let result = portable_safe_path(&root, "./"); - assert!( - result.is_err(), - "Le chemin « ./ » doit être refusé." - ); + assert!(result.is_err(), "Le chemin « ./ » doit être refusé."); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12887: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12904: ); portable_test_update_manifest(&root, |manifest| { - manifest["integrity"]["algorithm"] = - serde_json::json!("SHA-1"); + manifest["integrity"]["algorithm"] = serde_json::json!("SHA-1"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12912: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_ALGORITHM_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_ALGORITHM_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12941: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_MISSING")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12965: ); portable_test_update_manifest(&root, |manifest| { - manifest["integrity"].as_object_mut().unwrap() + manifest["integrity"] + .as_object_mut() + .unwrap() .remove("reference_manifests"); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12972: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_PATH_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_PATH_MISSING")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:12996: ); portable_test_update_manifest(&root, |manifest| { - manifest["integrity"]["reference_manifests"] = - serde_json::json!("empreintes/autres/"); + manifest["integrity"]["reference_manifests"] = serde_json::json!("empreintes/autres/"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13004: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_PATH_MISMATCH" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_PATH_MISMATCH")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13027: ); portable_test_update_manifest(&root, |manifest| { - manifest["integrity"]["reference_manifests"] = - serde_json::json!("../outside/"); + manifest["integrity"]["reference_manifests"] = serde_json::json!("../outside/"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13035: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_PATH_UNSAFE" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_PATH_UNSAFE")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13051: ); portable_test_update_manifest(&root, |manifest| { - manifest["integrity"]["verification_manifests"] = - serde_json::Value::Null; + manifest["integrity"]["verification_manifests"] = serde_json::Value::Null; }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13059: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "INTEGRITY_PATH_FOR_EXCLUDED_CATEGORY" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "INTEGRITY_PATH_FOR_EXCLUDED_CATEGORY")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13108: "count": 0 }); manifest["contents"]["included"] - .as_array_mut().unwrap().push(serde_json::json!("units")); + .as_array_mut() + .unwrap() + .push(serde_json::json!("units")); manifest["contents"]["excluded"] - .as_array_mut().unwrap().retain( - |value| value.as_str() != Some("units") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("units")); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13119: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_PATH_OVERLAP" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_PATH_OVERLAP")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13136: std::fs::write( root.join("oeuvres/suppressions.json"), r#"{"version":1,"deletions":[]}"#, - ).unwrap(); + ) + .unwrap(); portable_test_update_manifest(&root, |manifest| { manifest["contents"]["suppressions"]["path"] = Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13145: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_PATH_OVERLAP" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_PATH_OVERLAP")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13161: false, ); - std::fs::create_dir_all(root.join("ressources/couvertures")) - .unwrap(); - std::fs::create_dir_all(root.join("ressources/documents")) - .unwrap(); + std::fs::create_dir_all(root.join("ressources/couvertures")).unwrap(); + std::fs::create_dir_all(root.join("ressources/documents")).unwrap(); portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13171: - .as_array_mut().unwrap().push(serde_json::json!("resources")); + .as_array_mut() + .unwrap() + .push(serde_json::json!("resources")); manifest["contents"]["excluded"] - .as_array_mut().unwrap().retain( - |value| value.as_str() != Some("resources") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("resources")); manifest["contents"]["resources"] = serde_json::json!({ "covers": { "path": "ressources/couvertures/", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13191: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "RESOURCE_PATH_OVERLAP" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "RESOURCE_PATH_OVERLAP")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13207: false, ); - std::fs::create_dir_all(root.join("ressources/couvertures/documents")) - .unwrap(); - std::fs::create_dir_all(root.join("ressources/illustrations")) - .unwrap(); + std::fs::create_dir_all(root.join("ressources/couvertures/documents")).unwrap(); + std::fs::create_dir_all(root.join("ressources/illustrations")).unwrap(); portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13217: - .as_array_mut().unwrap().push(serde_json::json!("resources")); + .as_array_mut() + .unwrap() + .push(serde_json::json!("resources")); manifest["contents"]["excluded"] - .as_array_mut().unwrap().retain( - |value| value.as_str() != Some("resources") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("resources")); manifest["contents"]["resources"] = serde_json::json!({ "covers": { "path": "ressources/couvertures/", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13237: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "RESOURCE_PATH_OVERLAP" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "RESOURCE_PATH_OVERLAP")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13253: true, ); - std::fs::create_dir_all(root.join("oeuvres/couvertures")) - .unwrap(); - std::fs::create_dir_all(root.join("ressources/illustrations")) - .unwrap(); - std::fs::create_dir_all(root.join("ressources/documents")) - .unwrap(); + std::fs::create_dir_all(root.join("oeuvres/couvertures")).unwrap(); + std::fs::create_dir_all(root.join("ressources/illustrations")).unwrap(); + std::fs::create_dir_all(root.join("ressources/documents")).unwrap(); portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13265: - .as_array_mut().unwrap().push(serde_json::json!("resources")); + .as_array_mut() + .unwrap() + .push(serde_json::json!("resources")); manifest["contents"]["excluded"] - .as_array_mut().unwrap().retain( - |value| value.as_str() != Some("resources") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("resources")); manifest["contents"]["resources"] = serde_json::json!({ "covers": { "path": "oeuvres/couvertures/", Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13285: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_PATH_OVERLAP" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_PATH_OVERLAP")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13313: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "UNSAFE_CATEGORY_PATH" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "UNSAFE_CATEGORY_PATH")); let _ = std::fs::remove_dir_all(root); let _ = std::fs::remove_dir_all(outside); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13343: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "MANIFEST_INVALID_FILE" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "MANIFEST_INVALID_FILE")); let _ = std::fs::remove_dir_all(root); let _ = std::fs::remove_dir_all(outside); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13370: std::fs::write( &external_work, r#"{"uuid":"12345678-1234-4234-8234-123456789abc"}"#, - ).unwrap(); + ) + .unwrap(); - symlink(&external_work, root.join("oeuvres/12345678-1234-4234-8234-123456789abc.json")) - .unwrap(); + symlink( + &external_work, + root.join("oeuvres/12345678-1234-4234-8234-123456789abc.json"), + ) + .unwrap(); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13380: - assert!(result.diagnostics.iter().any( - |item| item.code == "WORK_FILE_NOT_REGULAR" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "WORK_FILE_NOT_REGULAR")); assert_eq!( std::fs::read_to_string(&external_work).unwrap(), Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13425: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "MANIFEST_NOT_FOUND" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "MANIFEST_NOT_FOUND")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13456: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "valid_with_warnings"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSION_UUID_DUPLICATE" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSION_UUID_DUPLICATE")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13481: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "valid_with_warnings"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSION_DATE_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSION_DATE_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13500: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "UNSAFE_CATEGORY_PATH" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "UNSAFE_CATEGORY_PATH")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13525: std::fs::write( root.join("oeuvres/test.json"), r#"{"uuid":"12345678-1234-4234-8234-123456789abc"}"#, - ).unwrap(); + ) + .unwrap(); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13532: assert_eq!(result.status, "valid_with_warnings"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSED_WORK_FILE_PRESENT" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSED_WORK_FILE_PRESENT")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13575: assert!(!validate_portable_iso8601("2026-11-20T10:00:00")); } - - #[test] fn portable_analyzer_rejects_invalid_category_counts() { let cases = [ Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13594: ); portable_test_update_manifest(&root, |manifest| { - let works = manifest["contents"]["works"] - .as_object_mut().unwrap(); + let works = manifest["contents"]["works"].as_object_mut().unwrap(); match value { Some(ref invalid) => { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13610: let result = analyze_portable_library_internal(&root); assert!( - result.diagnostics.iter().any(|item| - item.code == "CATEGORY_COUNT_INVALID" - && item.path.as_deref() == Some("contents.works.count") - ), + result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_COUNT_INVALID" + && item.path.as_deref() == Some("contents.works.count")), "Le compteur {label} aurait dû être rejeté : {:?}", result.diagnostics, ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13639: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "valid"); - assert!( - !result.diagnostics.iter().any(|item| - item.code == "CATEGORY_COUNT_INVALID" - ) - ); + assert!(!result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_COUNT_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13668: portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!("resources")); manifest["contents"]["excluded"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13675: - .as_array_mut().unwrap() - .retain(|value| - value.as_str() != Some("resources") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("resources")); manifest["contents"]["resources"] = serde_json::json!({ "covers": { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13693: }); manifest["contents"]["resources"][resource] - .as_object_mut().unwrap() + .as_object_mut() + .unwrap() .remove("count"); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13700: let result = analyze_portable_library_internal(&root); - let expected_path = - format!("contents.resources.{resource}.count"); + let expected_path = format!("contents.resources.{resource}.count"); assert!( - result.diagnostics.iter().any(|item| - item.code == "RESOURCE_COUNT_INVALID" - && item.path.as_deref() == Some(expected_path.as_str()) - ), + result + .diagnostics + .iter() + .any(|item| item.code == "RESOURCE_COUNT_INVALID" + && item.path.as_deref() == Some(expected_path.as_str())), "Le compteur de {resource} aurait dû être obligatoire : {:?}", result.diagnostics, ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13734: portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!("resources")); manifest["contents"]["excluded"] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13741: - .as_array_mut().unwrap() - .retain(|value| - value.as_str() != Some("resources") - ); + .as_array_mut() + .unwrap() + .retain(|value| value.as_str() != Some("resources")); manifest["contents"]["resources"] = serde_json::json!({ "covers": { Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13762: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "valid"); - assert!( - !result.diagnostics.iter().any(|item| - item.code == "RESOURCE_COUNT_INVALID" - ) - ); + assert!(!result + .diagnostics + .iter() + .any(|item| item.code == "RESOURCE_COUNT_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13784: manifest["extensions"]["vendor_example"] = serde_json::json!({"custom_field": "preserved"}); - manifest["contents"]["vendor_category"] = - serde_json::json!({"custom_value": 42}); + manifest["contents"]["vendor_category"] = serde_json::json!({"custom_value": 42}); manifest["contents"]["works"]["extensions"] = serde_json::json!({"vendor_work": {"enabled": true}}); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13792: - manifest["unknown_top_level_field"] = - serde_json::json!("tolerated"); + manifest["unknown_top_level_field"] = serde_json::json!("tolerated"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13806: let _ = std::fs::remove_dir_all(root); } - - #[test] fn portable_analyzer_rejects_invalid_format() { let root = portable_test_library( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13824: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "FORMAT_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "FORMAT_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13848: false, ); - portable_test_update_manifest(&root, |manifest| { - match value { - Some(ref version) => { - manifest["format_version"] = version.clone(); - } - None => { - manifest.as_object_mut().unwrap() - .remove("format_version"); - } + portable_test_update_manifest(&root, |manifest| match value { + Some(ref version) => { + manifest["format_version"] = version.clone(); } + None => { + manifest.as_object_mut().unwrap().remove("format_version"); + } }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13864: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "FORMAT_VERSION_UNSUPPORTED" - ), "Version {label} non rejetée : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "FORMAT_VERSION_UNSUPPORTED"), + "Version {label} non rejetée : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13881: ); portable_test_update_manifest(&root, |manifest| { - manifest["library"]["uuid"] = - serde_json::json!("12345678-1234-3234-8234-123456789abc"); + manifest["library"]["uuid"] = serde_json::json!("12345678-1234-3234-8234-123456789abc"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13889: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_UUID_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_UUID_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13905: ); portable_test_update_manifest(&root, |manifest| { - manifest["library"].as_object_mut().unwrap() - .remove("uuid"); + manifest["library"].as_object_mut().unwrap().remove("uuid"); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13913: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_UUID_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_UUID_MISSING")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13935: false, ); - portable_test_update_manifest(&root, |manifest| { - match value { - Some(name) => { - manifest["library"]["name"] = - serde_json::json!(name); - } - None => { - manifest["library"].as_object_mut().unwrap() - .remove("name"); - } + portable_test_update_manifest(&root, |manifest| match value { + Some(name) => { + manifest["library"]["name"] = serde_json::json!(name); } + None => { + manifest["library"].as_object_mut().unwrap().remove("name"); + } }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13952: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_NAME_MISSING" - ), "Nom {label} non rejeté : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_NAME_MISSING"), + "Nom {label} non rejeté : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13975: false, ); - portable_test_update_manifest(&root, |manifest| { - match value { - Some(date) => { - manifest["library"]["created_at"] = - serde_json::json!(date); - } - None => { - manifest["library"].as_object_mut().unwrap() - .remove("created_at"); - } + portable_test_update_manifest(&root, |manifest| match value { + Some(date) => { + manifest["library"]["created_at"] = serde_json::json!(date); } + None => { + manifest["library"] + .as_object_mut() + .unwrap() + .remove("created_at"); + } }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:13998: "LIBRARY_DATE_INVALID" }; - assert!(result.diagnostics.iter().any( - |item| item.code == expected_code - ), "Date {label} non rejetée : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == expected_code), + "Date {label} non rejetée : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14018: false, ); - portable_test_update_manifest(&root, |manifest| { - match label { - "missing" => { - manifest.as_object_mut().unwrap() - .remove("library"); - } - "null" => { - manifest["library"] = serde_json::Value::Null; - } - _ => { - manifest["library"] = - serde_json::json!("Bibliothèque"); - } + portable_test_update_manifest(&root, |manifest| match label { + "missing" => { + manifest.as_object_mut().unwrap().remove("library"); } + "null" => { + manifest["library"] = serde_json::Value::Null; + } + _ => { + manifest["library"] = serde_json::json!("Bibliothèque"); + } }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14039: assert_eq!(result.status, "invalid"); if label == "missing" { - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_SECTION_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_SECTION_MISSING")); } else { - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_UUID_MISSING" - )); - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_NAME_MISSING" - )); - assert!(result.diagnostics.iter().any( - |item| item.code == "LIBRARY_DATE_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_UUID_MISSING")); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_NAME_MISSING")); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "LIBRARY_DATE_MISSING")); } let _ = std::fs::remove_dir_all(root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14058: } } - - #[test] fn portable_analyzer_rejects_missing_or_invalid_category_lists() { let cases = [ Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14077: false, ); - portable_test_update_manifest(&root, |manifest| { - match label { - "included_missing" => { - manifest["contents"].as_object_mut().unwrap() - .remove("included"); - } - "excluded_missing" => { - manifest["contents"].as_object_mut().unwrap() - .remove("excluded"); - } - "included_invalid" => { - manifest["contents"]["included"] = - serde_json::json!("suppressions"); - } - _ => { - manifest["contents"]["excluded"] = - serde_json::Value::Null; - } + portable_test_update_manifest(&root, |manifest| match label { + "included_missing" => { + manifest["contents"] + .as_object_mut() + .unwrap() + .remove("included"); } + "excluded_missing" => { + manifest["contents"] + .as_object_mut() + .unwrap() + .remove("excluded"); + } + "included_invalid" => { + manifest["contents"]["included"] = serde_json::json!("suppressions"); + } + _ => { + manifest["contents"]["excluded"] = serde_json::Value::Null; + } }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14102: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_LIST_MISSING" - ), "Liste {label} non rejetée : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_LIST_MISSING"), + "Liste {label} non rejetée : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14120: portable_test_update_manifest(&root, |manifest| { manifest["contents"]["included"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!(42)); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14127: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_NAME_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_NAME_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14148: portable_test_update_manifest(&root, |manifest| { manifest["contents"][label] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!("vendor_category")); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14155: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_UNKNOWN" - ), "Catégorie inconnue dans {label} non rejetée : {:?}", - result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_UNKNOWN"), + "Catégorie inconnue dans {label} non rejetée : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14178: portable_test_update_manifest(&root, |manifest| { manifest["contents"][label] - .as_array_mut().unwrap() - .push(serde_json::json!( - if label == "included" { - "suppressions" - } else { - "works" - } - )); + .as_array_mut() + .unwrap() + .push(serde_json::json!(if label == "included" { + "suppressions" + } else { + "works" + })); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14192: assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_DUPLICATE" - ), "Doublon dans {label} non rejeté : {:?}", - result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_DUPLICATE"), + "Doublon dans {label} non rejeté : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14211: portable_test_update_manifest(&root, |manifest| { manifest["contents"]["excluded"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .push(serde_json::json!("suppressions")); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14218: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_DUPLICATE" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_DUPLICATE")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14236: portable_test_update_manifest(&root, |manifest| { manifest["contents"]["excluded"] - .as_array_mut().unwrap() + .as_array_mut() + .unwrap() .retain(|value| value.as_str() != Some("works")); }); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14243: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "CATEGORY_UNDECLARED" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "CATEGORY_UNDECLARED")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14252: - - #[test] fn portable_analyzer_reports_multiple_independent_diagnostics() { let root = portable_test_library( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14305: std::fs::remove_dir_all(&root).unwrap(); } - #[test] fn portable_analyzer_rejects_invalid_suppression_json() { let root = portable_test_library( Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14318: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSIONS_JSON_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSIONS_JSON_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14337: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSIONS_VERSION_INVALID" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSIONS_VERSION_INVALID")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14362: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSIONS_LIST_INVALID" - ), "Structure {label} non rejetée : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSIONS_LIST_INVALID"), + "Structure {label} non rejetée : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14396: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == expected_code - ), "Diagnostic {expected_code} absent : {:?}", result.diagnostics); + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == expected_code), + "Diagnostic {expected_code} absent : {:?}", + result.diagnostics + ); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14416: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "valid_with_warnings"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSION_DATE_MISSING" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSION_DATE_MISSING")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14433: ); portable_test_update_manifest(&root, |manifest| { - manifest["contents"]["suppressions"]["count"] = - serde_json::json!(1); + manifest["contents"]["suppressions"]["count"] = serde_json::json!(1); }); let result = analyze_portable_library_internal(&root); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14441: assert_eq!(result.status, "valid_with_warnings"); - assert!(result.diagnostics.iter().any( - |item| item.code == "SUPPRESSION_COUNT_MISMATCH" - )); + assert!(result + .diagnostics + .iter() + .any(|item| item.code == "SUPPRESSION_COUNT_MISMATCH")); let _ = std::fs::remove_dir_all(root); } Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14472: let result = analyze_portable_library_internal(&root); assert_eq!(result.status, "invalid"); - assert!(result.diagnostics.iter().any( - |item| item.code == "UNSAFE_CATEGORY_PATH" - ), "Le lien symbolique intermédiaire n'a pas été détecté : {:?}", + assert!( + result + .diagnostics + .iter() + .any(|item| item.code == "UNSAFE_CATEGORY_PATH"), + "Le lien symbolique intermédiaire n'a pas été détecté : {:?}", result.diagnostics ); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14482: let _ = std::fs::remove_dir_all(outside); } - #[test] fn custom_relation_types_support_multiple_relations_and_inverse() { let mut connection = test_connection(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14522: ..Default::default() }, &relation_types, - ).unwrap(); + ) + .unwrap(); - let works = list_works_with_relation_types( - &connection, - &relation_types, - ).unwrap(); + let works = list_works_with_relation_types(&connection, &relation_types).unwrap(); - let created = works.iter() - .find(|work| work.id == work_id) - .unwrap(); + let created = works.iter().find(|work| work.id == work_id).unwrap(); - let direct: Vec<&WorkRelation> = created.relations.iter() + let direct: Vec<&WorkRelation> = created + .relations + .iter() .filter(|relation| relation.key == "sequel") .collect(); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14542: assert!(direct.iter().any(|relation| relation.id == Some(1))); assert!(direct.iter().any(|relation| relation.id == Some(2))); - let first_target = works.iter() - .find(|work| work.id == 1) - .unwrap(); + let first_target = works.iter().find(|work| work.id == 1).unwrap(); - let inverse = first_target.relations.iter() - .find(|relation| { - relation.key == "prequel" && relation.id == Some(work_id) - }) + let inverse = first_target + .relations + .iter() + .find(|relation| relation.key == "prequel" && relation.id == Some(work_id)) .expect("La relation inverse doit apparaître sur la fiche cible"); assert_eq!(inverse.label, "Précédée de"); Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14559: fn custom_relation_without_inverse_stays_direct_only() { let mut connection = test_connection(); - let relation_types = vec![ - RelationType { - key: "inspired_by".to_string(), - label: "Inspirée de".to_string(), - inverse: None, - active: true, - }, - ]; + let relation_types = vec![RelationType { + key: "inspired_by".to_string(), + label: "Inspirée de".to_string(), + inverse: None, + active: true, + }]; let work_id = create_work_with_relation_types( &mut connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14573: CreateWorkInput { original: "Œuvre inspirée".to_string(), form: "Animation".to_string(), - adaptations: vec![ - CreateWorkAdaptation { - direction: "inspired_by".to_string(), - related_work_id: Some(1), - related_work_title: None, - }, - ], + adaptations: vec![CreateWorkAdaptation { + direction: "inspired_by".to_string(), + related_work_id: Some(1), + related_work_title: None, + }], ..Default::default() }, &relation_types, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14586: - ).unwrap(); + ) + .unwrap(); - let works = list_works_with_relation_types( - &connection, - &relation_types, - ).unwrap(); + let works = list_works_with_relation_types(&connection, &relation_types).unwrap(); - let created = works.iter() - .find(|work| work.id == work_id) - .unwrap(); + let created = works.iter().find(|work| work.id == work_id).unwrap(); assert!(created.relations.iter().any(|relation| { relation.key == "inspired_by" Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14600: && relation.id == Some(1) })); - let target = works.iter() - .find(|work| work.id == 1) - .unwrap(); + let target = works.iter().find(|work| work.id == 1).unwrap(); - assert!(!target.relations.iter().any(|relation| { - relation.id == Some(work_id) - })); + assert!(!target + .relations + .iter() + .any(|relation| { relation.id == Some(work_id) })); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14633: CreateWorkInput { original: "Œuvre créée avant désactivation".to_string(), form: "Animation".to_string(), - adaptations: vec![ - CreateWorkAdaptation { - direction: "sequel".to_string(), - related_work_id: Some(1), - related_work_title: None, - }, - ], + adaptations: vec![CreateWorkAdaptation { + direction: "sequel".to_string(), + related_work_id: Some(1), + related_work_title: None, + }], ..Default::default() }, &active_types, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14646: - ).unwrap(); + ) + .unwrap(); let mut inactive_types = active_types.clone(); - inactive_types.iter_mut() + inactive_types + .iter_mut() .find(|relation_type| relation_type.key == "sequel") .unwrap() .active = false; Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14653: - let works = list_works_with_relation_types( - &connection, - &inactive_types, - ).unwrap(); + let works = list_works_with_relation_types(&connection, &inactive_types).unwrap(); - let created = works.iter() - .find(|work| work.id == work_id) - .unwrap(); + let created = works.iter().find(|work| work.id == work_id).unwrap(); assert!(created.relations.iter().any(|relation| { - relation.key == "sequel" - && relation.label == "Suite de" - && relation.id == Some(1) + relation.key == "sequel" && relation.label == "Suite de" && relation.id == Some(1) })); - let target = works.iter() - .find(|work| work.id == 1) - .unwrap(); + let target = works.iter().find(|work| work.id == 1).unwrap(); - assert!(target.relations.iter().any(|relation| { - relation.key == "prequel" - && relation.id == Some(work_id) - })); + assert!(target + .relations + .iter() + .any(|relation| { relation.key == "prequel" && relation.id == Some(work_id) })); let result = create_work_with_relation_types( &mut connection, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14680: CreateWorkInput { original: "Nouvelle œuvre refusée".to_string(), form: "Animation".to_string(), - adaptations: vec![ - CreateWorkAdaptation { - direction: "sequel".to_string(), - related_work_id: Some(2), - related_work_title: None, - }, - ], + adaptations: vec![CreateWorkAdaptation { + direction: "sequel".to_string(), + related_work_id: Some(2), + related_work_title: None, + }], ..Default::default() }, &inactive_types, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14693: ); assert!(result.is_err()); - assert!(result.unwrap_err().contains("n'existe pas ou n'est plus actif")); + assert!(result + .unwrap_err() + .contains("n'existe pas ou n'est plus actif")); } #[test] Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14720: CreateWorkInput { original: "Œuvre historique".to_string(), form: "Animation".to_string(), - adaptations: vec![ - CreateWorkAdaptation { - direction: "sequel".to_string(), - related_work_id: Some(1), - related_work_title: None, - }, - ], + adaptations: vec![CreateWorkAdaptation { + direction: "sequel".to_string(), + related_work_id: Some(1), + related_work_title: None, + }], ..Default::default() }, &relation_types, Diff in /home/guidelumineux/Bibliotheca-Test/bibliotheca-app/src-tauri/src/lib.rs:14733: - ).unwrap(); + ) + .unwrap(); // Un catalogue vide simule le retrait complet des deux types. - let works = list_works_with_relation_types( - &connection, - &[], - ).unwrap(); + let works = list_works_with_relation_types(&connection, &[]).unwrap(); - let created = works.iter() - .find(|work| work.id == work_id) - .unwrap(); + let created = works.iter().find(|work| work.id == work_id).unwrap(); assert!(created.relations.iter().any(|relation| { - relation.key == "sequel" - && relation.label == "Suite de" - && relation.id == Some(1) + relation.key == "sequel" && relation.label == "Suite de" && relation.id == Some(1) })); - let target = works.iter() - .find(|work| work.id == 1) - .unwrap(); + let target = works.iter().find(|work| work.id == 1).unwrap(); - assert!(!target.relations.iter().any(|relation| { - relation.id == Some(work_id) - })); + assert!(!target + .relations + .iter() + .any(|relation| { relation.id == Some(work_id) })); } - } guidelumineux@fairytail01:~/Bibliotheca-Test/bibliotheca-app$