Struct TreeProcessor

Source
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::Dirs 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 added after their parent directories. If this happens, WriteOrder will be raised and the node will not be added.

Implementations§

Source§

impl TreeProcessor

Source

pub fn new<P: AsRef<Path>>(outfile: P) -> Result<Self>

Create a new TreeProcessor for an output file.

Source

pub fn add(&self, source: SourceFile) -> Result<u32>

Add a new file to the archive.

It is not recommended to call this on SourceFiles that were not yielded by iter.

Source

pub fn finish(&self) -> Result<()>

Finish writing the archive.

Source

pub fn iter<'a, P: AsRef<Path>>(&'a self, root: P) -> TreeIterator<'a>

Create an iterator over a directory tree, yielding them in a form suitable to pass to add.

Source

pub fn process<P: AsRef<Path>>(self, root: P) -> Result<()>

Add an entire directory tree to the archive, then finish it.

This is the most basic, bare-bones way to create a full archive from an existing directory tree. This offers no way to customize the archive or handle errors gracefully.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T