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>
impl<'a> Node<'a>
Sourcepub fn xattrs(&self, category: XattrType) -> Result<HashMap<Vec<u8>, Vec<u8>>>
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.
Sourcepub fn id(&self) -> u32
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.
Sourcepub fn path(&self) -> Option<&Path>
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
.
Sourcepub fn name(&self) -> Option<String>
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
.
Sourcepub fn parent(&self) -> Result<Self>
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.
Sourcepub fn resolve_exists(&self) -> Result<Self>
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.
Sourcepub fn resolve(&self) -> Result<Option<Self>>
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.
Sourcepub fn is_file(&self) -> Result<bool>
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.
Sourcepub fn into_owned_file(self) -> Result<OwnedFile<'a>>
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)?;
Sourcepub fn into_owned_dir(self) -> Result<OwnedDir<'a>>
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());
}