MCPcopy Create free account
hub / github.com/Michael-F-Bryan/include_dir / extract

Method extract

include_dir/src/dir.rs:77–95  ·  view source on GitHub ↗

Create directories and extract all files to real filesystem. Creates parent directories of `path` if they do not already exist. Fails if some files already exist. In case of error, partially extracted directory may remain on the filesystem.

(&self, base_path: S)

Source from the content-addressed store, hash-verified

75 /// Fails if some files already exist.
76 /// In case of error, partially extracted directory may remain on the filesystem.
77 pub fn extract<S: AsRef<Path>>(&self, base_path: S) -> std::io::Result<()> {
78 let base_path = base_path.as_ref();
79
80 for entry in self.entries() {
81 let path = base_path.join(entry.path());
82
83 match entry {
84 DirEntry::Dir(d) => {
85 fs::create_dir_all(&path)?;
86 d.extract(base_path)?;
87 }
88 DirEntry::File(f) => {
89 fs::write(path, f.contents())?;
90 }
91 }
92 }
93
94 Ok(())
95 }
96}

Callers 1

extract_all_filesFunction · 0.80

Calls 3

entriesMethod · 0.80
contentsMethod · 0.80
pathMethod · 0.45

Tested by 1

extract_all_filesFunction · 0.64