Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW
✓ CI success Fintan Halpenny committed 5 months ago
commit 15bfda0459489259f2d578e15ba9db8186aca7ad
parent c2d2c529b0c4b9878e615212a9c9b3c6c845b6c4
3 passed (3 total) View logs
1 file changed +35 -10
modified crates/radicle/src/profile.rs
@@ -557,7 +557,7 @@ impl Home {
            path: dunce::canonicalize(path)?,
        };

-
        for dir in &[home.storage(), home.keys(), home.node(), home.cobs()] {
+
        for dir in &home.subdirectories() {
            if !dir.exists() {
                fs::create_dir_all(dir)?;
            }
@@ -566,8 +566,20 @@ impl Home {
        Ok(home)
    }

-
    fn load(home: impl Into<PathBuf>) -> Result<Self, io::Error> {
-
        let path = home.into();
+
    /// Load existing Radicle Home directories.
+
    ///
+
    /// The `home` path is the expected base directory for all necessary
+
    /// subdirectories.
+
    ///
+
    /// # Errors
+
    ///
+
    /// If `home` or any of the subdirectories are missing an [`io::Error`] is
+
    /// returned.
+
    pub fn load<P>(home: P) -> Result<Self, io::Error>
+
    where
+
        P: AsRef<Path>,
+
    {
+
        let path = home.as_ref();
        if !path.exists() {
            return Err(io::Error::new(
                io::ErrorKind::NotFound,
@@ -578,18 +590,31 @@ impl Home {
            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()),
-
                ));
-
            }
+
        let missing = home
+
            .subdirectories()
+
            .into_iter()
+
            .filter(|dir| !dir.exists())
+
            .collect::<Vec<_>>();
+

+
        if !missing.is_empty() {
+
            let missing = missing
+
                .into_iter()
+
                .map(|dir| dir.display().to_string())
+
                .collect::<Vec<_>>()
+
                .join(",");
+
            return Err(io::Error::new(
+
                io::ErrorKind::NotFound,
+
                format!("Required Radicle directories are missing: [{}]", missing),
+
            ));
        }

        Ok(home)
    }

+
    fn subdirectories(&self) -> [PathBuf; 4] {
+
        [self.storage(), self.keys(), self.node(), self.cobs()]
+
    }
+

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