pub struct TreeProcessor { /* private fields */ }
Expand description
Tool to help create an archive from a directory in the filesystem.
This wraps a Writer
and takes care of tracking the directory hierarchy as files are added,
populating the iterators of SourceData::Dir
s as necessary.
To simply create a SquashFS file from a chosen directory, call process
:
TreeProcessor::new("archive.sfs")?.process("/home/me/test")?;
For more control over the addition process – for example, to exclude certain files, add
extended attributes, ignore errors, or print files as they are added – use
iter
to get an iterator over the directory tree, and then call
add
on each SourceFile
yielded after applying any desired transformations.
After the iterator finishes, remember to call finish
.
let processor = TreeProcessor::new("archive.sfs")?;
for mut entry in processor.iter("/home/me/test") {
entry.content.mode = 0x1ff; // Set all nodes to be read/writable by anyone
match processor.add(entry) {
Ok(id) => println!("{}: {}", id, entry.path),
Err(_) => println!("Failed adding {}", entry.path),
}
}
processor.finish()?;
It is safe to process the tree using multiple threads, but it is the caller’s responsibility
to ensure that any out-of-order execution does not cause child nodes to be add
ed after their
parent directories. If this happens, WriteOrder
will be
raised and the node will not be added.
Implementations§
Source§impl TreeProcessor
impl TreeProcessor
Sourcepub fn new<P: AsRef<Path>>(outfile: P) -> Result<Self>
pub fn new<P: AsRef<Path>>(outfile: P) -> Result<Self>
Create a new TreeProcessor
for an output file.
Sourcepub fn add(&self, source: SourceFile) -> Result<u32>
pub fn add(&self, source: SourceFile) -> Result<u32>
Add a new file to the archive.
It is not recommended to call this on SourceFile
s that were not yielded by iter
.