pinakes-core: update remaining modules and tests

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I9e0ff5ea33a5cf697473423e88f167ce6a6a6964
This commit is contained in:
raf 2026-03-08 00:42:29 +03:00
commit 3d9f8933d2
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
44 changed files with 1207 additions and 578 deletions

View file

@ -4,6 +4,7 @@ use super::DeviceSyncState;
use crate::config::ConflictResolution;
/// Detect if there's a conflict between local and server state.
#[must_use]
pub fn detect_conflict(state: &DeviceSyncState) -> Option<ConflictInfo> {
// If either side has no hash, no conflict possible
let local_hash = state.local_hash.as_ref()?;
@ -48,6 +49,7 @@ pub enum ConflictOutcome {
}
/// Resolve a conflict based on the configured strategy.
#[must_use]
pub fn resolve_conflict(
conflict: &ConflictInfo,
resolution: ConflictResolution,
@ -67,20 +69,21 @@ pub fn resolve_conflict(
}
/// Generate a new path for the conflicting local file.
/// Format: filename.conflict-<short_hash>.ext
/// Format: filename.conflict-<`short_hash>.ext`
fn generate_conflict_path(original_path: &str, local_hash: &str) -> String {
let short_hash = &local_hash[..8.min(local_hash.len())];
if let Some((base, ext)) = original_path.rsplit_once('.') {
format!("{}.conflict-{}.{}", base, short_hash, ext)
format!("{base}.conflict-{short_hash}.{ext}")
} else {
format!("{}.conflict-{}", original_path, short_hash)
format!("{original_path}.conflict-{short_hash}")
}
}
/// Automatic conflict resolution based on modification times.
/// Useful when ConflictResolution is set to a time-based strategy.
pub fn resolve_by_mtime(conflict: &ConflictInfo) -> ConflictOutcome {
/// Useful when `ConflictResolution` is set to a time-based strategy.
#[must_use]
pub const fn resolve_by_mtime(conflict: &ConflictInfo) -> ConflictOutcome {
match (conflict.local_mtime, conflict.server_mtime) {
(Some(local), Some(server)) => {
if local > server {