Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle: Add a `load` method to `radicle::profile::Home`
Sebastian Martinez committed 5 months ago
commit edf991a2ff9fbfa626430c0437cf470e66feb767
parent 6d0c571ea9998dd98bf10cc191848029f5210d8a
1 file changed +24 -0
modified crates/radicle/src/profile.rs
@@ -574,6 +574,30 @@ impl Home {
        Ok(home)
    }

+
    fn load(home: impl Into<PathBuf>) -> Result<Self, io::Error> {
+
        let path = home.into();
+
        if !path.exists() {
+
            return Err(io::Error::new(
+
                io::ErrorKind::NotFound,
+
                format!("Radicle home directory does not exist: {}", path.display()),
+
            ));
+
        }
+
        let home = Self {
+
            path: dunce::canonicalize(path)?,
+
        };
+

+
        for dir in &[home.storage(), home.keys(), home.node(), home.cobs()] {
+
            if !dir.exists() {
+
                return Err(io::Error::new(
+
                    io::ErrorKind::NotFound,
+
                    format!("Required Radicle directory is missing: {}. This may indicate an incomplete or corrupted Radicle profile.", dir.display()),
+
                ));
+
            }
+
        }
+

+
        Ok(home)
+
    }
+

    pub fn path(&self) -> &Path {
        self.path.as_path()
    }