oximedia_proxy/conform/
relink.rs1use crate::{ProxyLinkManager, Result};
4use std::path::{Path, PathBuf};
5
6pub struct Relinker<'a> {
8 link_manager: &'a ProxyLinkManager,
9}
10
11impl<'a> Relinker<'a> {
12 #[must_use]
14 pub const fn new(link_manager: &'a ProxyLinkManager) -> Self {
15 Self { link_manager }
16 }
17
18 pub fn relink(&self, proxy_path: &Path) -> Result<PathBuf> {
24 self.link_manager
25 .get_original(proxy_path)
26 .map(|p| p.to_path_buf())
27 }
28
29 pub fn relink_batch(&self, proxy_paths: &[PathBuf]) -> Vec<RelinkResult> {
31 proxy_paths
32 .iter()
33 .map(|proxy| match self.relink(proxy) {
34 Ok(original) => RelinkResult::Success {
35 proxy: proxy.clone(),
36 original,
37 },
38 Err(e) => RelinkResult::Failed {
39 proxy: proxy.clone(),
40 error: e.to_string(),
41 },
42 })
43 .collect()
44 }
45}
46
47#[derive(Debug, Clone)]
49pub enum RelinkResult {
50 Success {
52 proxy: PathBuf,
54 original: PathBuf,
56 },
57 Failed {
59 proxy: PathBuf,
61 error: String,
63 },
64}
65
66impl RelinkResult {
67 #[must_use]
69 pub const fn is_success(&self) -> bool {
70 matches!(self, Self::Success { .. })
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 #[test]
79 fn test_relink_result() {
80 let result = RelinkResult::Success {
81 proxy: PathBuf::from("proxy.mp4"),
82 original: PathBuf::from("original.mov"),
83 };
84
85 assert!(result.is_success());
86 }
87}