| 29 | } |
| 30 | |
| 31 | pub fn parse_path(input: &str) -> Result<(DataRoot, RepoId, ExternalId)> { |
| 32 | lazy_static! { |
| 33 | static ref RE: Regex = |
| 34 | Regex::new(r"^(.+?)/([\w-]+)/objects/([\w_-]{2})/([\w_-]{2})/([\w_-]+)/object.yaml$") |
| 35 | .unwrap(); |
| 36 | } |
| 37 | |
| 38 | let cap = RE |
| 39 | .captures(input) |
| 40 | .ok_or_else(|| Error::Repo(format!("bad path: {input}")))?; |
| 41 | if cap.len() != 6 { |
| 42 | return Err(Error::Command(format!("bad path: {cap:?}"))); |
| 43 | } |
| 44 | |
| 45 | let (root, repo_id, part1, part2, part3) = |
| 46 | match (cap.get(1), cap.get(2), cap.get(3), cap.get(4), cap.get(5)) { |
| 47 | (Some(root), Some(repo_id), Some(part1), Some(part2), Some(part3)) => ( |
| 48 | root.as_str(), |
| 49 | RepoId::try_from(repo_id.as_str())?, |
| 50 | part1.as_str(), |
| 51 | part2.as_str(), |
| 52 | part3.as_str(), |
| 53 | ), |
| 54 | _ => return Err(Error::Repo(format!("bad path: {input}"))), |
| 55 | }; |
| 56 | |
| 57 | let oid: ExternalId = format!("{part1}{part2}{part3}").try_into()?; |
| 58 | let root = PathBuf::from(root); |
| 59 | |
| 60 | Ok((DataRoot::new(root), repo_id, oid)) |
| 61 | } |
| 62 | |
| 63 | impl DataRoot { |
| 64 | pub fn new(root: PathBuf) -> Self { |