pinakes-core: update remaining modules and tests
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I9e0ff5ea33a5cf697473423e88f167ce6a6a6964
This commit is contained in:
parent
c8425a4c34
commit
3d9f8933d2
44 changed files with 1207 additions and 578 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue