Struct Node

Source
pub struct Node<'a> { /* private fields */ }
Expand description

Information about a single node in the directory tree.

This corresponds to the inode and directory entry structures of the underlying library. Because SquashFS inodes do not retain pointers back to their directory entries, inodes by default have no information about their positions in the directory tree. To work around this, a Node struct stores its path and propagate it through calls like child and parent. If the Node was originally constructed in a way that does not provide path information, such as retrieving a node by inode number using Archive::get_id, then the methods that require knowledge of the node’s location in the tree, such as path and parent, will fail. For this reason, it is generally recommended to get nodes by path when possible.

Implementations§

Source§

impl<'a> Node<'a>

Source

pub fn xattrs(&self, category: XattrType) -> Result<HashMap<Vec<u8>, Vec<u8>>>

Get a node’s extended attributes in a given namespace as a map of byte Vecs.

Source

pub fn id(&self) -> u32

Get the inode number of a node.

This can be used to cheaply compare nodes for equality or can be later used with get_id to retrieve nodes without traversing the directory tree.

Source

pub fn data(&self) -> Result<Data<'_>>

Retrieve the data stored at the node.

Source

pub fn path(&self) -> Option<&Path>

Get the absolute path to the node in the archive.

If the node was obtained in a way that did not provide path information, this will return None. If the node was retrieved using Archive::get, this should return Some.

Source

pub fn name(&self) -> Option<String>

A convenience method to retrieve the file name of the node from its path.

As with path, if the node does not have embedded path information, this will return None.

Source

pub fn parent(&self) -> Result<Self>

Get the parent directory node of the current node.

If the node is the root of the tree, it will return a copy of itself. If this node was created without path information, it will raise a NoPath error.

Source

pub fn resolve_exists(&self) -> Result<Self>

Resolve symbolic links to their targets, raising an error if a target does not exist.

This works the same way as resolve, except that an error is raised if any link in the chain of symbolic links points at a path that does not exist.

Source

pub fn resolve(&self) -> Result<Option<Self>>

Resolve symbolic links to their targets.

This follows the chain of symbolic links starting at the current node all the way to the end, returning the final node, which is guaranteed not to be a symbolic link. If any link in the chain points at a path that does not exist, it returns Ok(None). If the current node is not a sybmolic link, this returns a copy of itself.

Source

pub fn is_file(&self) -> Result<bool>

Return true if the current Node is a file.

This does not resolve symbolic links, and will return false when called on nodes that are symbolic links to files.

Source

pub fn as_file(&self) -> Result<File<'_>>

Fetch the File object from the current Node.

This is essentially a shortcut for if let Data::File(file) = self.data(). If this node is not a regular file, this will return an error. This does not resolve symbolic links; the caller should call resolve first if the node could be a link.

Source

pub fn into_owned_file(self) -> Result<OwnedFile<'a>>

Convert the Node into an OwnedFile.

This resolves symbolic links. If the current node is not a regular file or a link to one, it will return an error.

let archive = Archive::new("archive.sfs")?;
let mut buf = String::new();
archive.get("/file.txt")?.unwrap().into_owned_file()?.read_to_string(&mut buf)?;
Source

pub fn is_dir(&self) -> Result<bool>

Return true if the current Node is a directory.

Source

pub fn as_dir(&self) -> Result<Dir<'_>>

Fetch the Dir object from the current Node.

This is essentially a shortcut for if let Data::Dir(dir) = self.data(). If this node is not a directory, it will return an error. This does not resolve symbolic links; the caller should call resolve first if the node could be a link.

Source

pub fn into_owned_dir(self) -> Result<OwnedDir<'a>>

Convert the Node into an OwnedDir.

This resolves symbolic links. If the current node is not a directory or a link to one, it will return an error.

let archive = Archive::new("archive.sfs")?;
for child in archive.get("/dir")?.unwrap().into_owned_dir()? {
    println!("{}", child?.name());
}
Source

pub fn uid(&self) -> Result<u32>

Get the UID of the Node.

Source

pub fn gid(&self) -> Result<u32>

Get the GID of the Node.

Source

pub fn mode(&self) -> u16

Get the file mode of the Node.

Source

pub fn mtime(&self) -> u32

Get the modification time of the Node as a UNIX timestamp.

Trait Implementations§

Source§

impl<'a> Clone for Node<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Node<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Display for Node<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Node<'a>

§

impl<'a> RefUnwindSafe for Node<'a>

§

impl<'a> !Send for Node<'a>

§

impl<'a> !Sync for Node<'a>

§

impl<'a> Unpin for Node<'a>

§

impl<'a> UnwindSafe for Node<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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