Skip to main content

replication_destination_differs

Function replication_destination_differs 

Source
pub fn replication_destination_differs(source: &Backend, dest: &Backend) -> bool
Expand description

Whether a replication’s destination backend differs from its source repository’s backend (ADR-0005 §13(d)). Replicating a repository to itself is a no-op (or a loop), so the webhook rejects it. Pure so the decision is unit-tested; the webhook resolves the source backend (it has a client) and calls this. A “same” destination is detected structurally by [backend_target_key]: same backend kind AND the same identifying target — which for S3 includes the endpoint and region (not just bucket+prefix), for Azure the storage account, and for a filesystem the backing volume, so two distinct providers that share a bucket/container/path name are NOT mistaken for the same repository (#248).

use kopiur_api::backend::{Backend, FilesystemBackend, S3Backend};
use kopiur_api::validate::replication_destination_differs;

let fs_a = Backend::Filesystem(FilesystemBackend { path: "/a".into(), volume: None });
let fs_b = Backend::Filesystem(FilesystemBackend { path: "/b".into(), volume: None });
// Different paths → differ.
assert!(replication_destination_differs(&fs_a, &fs_b));
// Same path → same target (would be a self-replication).
assert!(!replication_destination_differs(&fs_a, &fs_a));
// Different backend kinds always differ.
let s3 = Backend::S3(S3Backend { bucket: "b".into(), prefix: None, endpoint: None, region: None, auth: None, tls: None });
assert!(replication_destination_differs(&fs_a, &s3));
// Same bucket name at two DIFFERENT S3 endpoints → distinct targets (#248).
let s3_nas = Backend::S3(S3Backend { bucket: "kopiur".into(), prefix: None, endpoint: Some("nas.example:3000".into()), region: None, auth: None, tls: None });
let s3_e2 = Backend::S3(S3Backend { bucket: "kopiur".into(), prefix: None, endpoint: Some("t3u7.fra3.idrivee2-58.com".into()), region: Some("eu-central-2".into()), auth: None, tls: None });
assert!(replication_destination_differs(&s3_nas, &s3_e2));