1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{Build, MergeableFileSystemTree};
use std::{
    fs::{create_dir_all, write},
    io::Error,
    path::{Path, PathBuf},
};

impl<Name, FileContent> Build<Name, Error> for MergeableFileSystemTree<Name, FileContent>
where
    Name: AsRef<Path> + Ord,
    FileContent: AsRef<[u8]>,
{
    type Path = PathBuf;

    fn join(prefix: &Self::Path, name: &Name) -> Self::Path {
        prefix.join(name)
    }

    fn write_file(path: &Self::Path, content: &Self::FileContent) -> Result<(), Error> {
        if let Some(dir) = path.parent() {
            create_dir_all(dir)?;
        }
        write(path, content)
    }

    fn create_dir(path: &Self::Path) -> Result<(), Error> {
        create_dir_all(path)
    }
}