run_git/
base_and_rel_path.rs

1use std::{ffi::OsStr, path::PathBuf, sync::Arc};
2
3#[derive(Debug, Clone)]
4pub struct BaseAndRelPath {
5    pub base_path: Option<Arc<PathBuf>>,
6    pub rel_path: PathBuf,
7}
8
9impl BaseAndRelPath {
10    pub fn new(base_path: Option<Arc<PathBuf>>, rel_path: PathBuf) -> Self {
11        Self {
12            base_path,
13            rel_path,
14        }
15    }
16
17    pub fn full_path(&self) -> PathBuf {
18        if let Some(path) = &self.base_path {
19            let mut path = (**path).to_owned();
20            path.push(&self.rel_path);
21            path
22        } else {
23            self.rel_path.clone()
24        }
25    }
26
27    pub fn extension(&self) -> Option<&OsStr> {
28        self.rel_path.extension()
29    }
30
31    pub fn rel_path(&self) -> &str {
32        self.rel_path
33            // XXX what happens on Windows? UTF-16 always needs recoding, no?
34            .to_str()
35            .expect("always works since created from str")
36    }
37}