Skip to content

Commit

Permalink
handles: add context to error for try_clone
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Jul 30, 2024
1 parent 2a00481 commit 8cb1ddf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

#![forbid(unsafe_code)]

use crate::{error::Error, flags::OpenFlags, procfs::PROCFS_HANDLE, utils::RawFdExt};
use crate::{
error::{Error, ErrorExt},
flags::OpenFlags,
procfs::PROCFS_HANDLE,
utils::RawFdExt,
};

use std::fs::File;

Expand Down Expand Up @@ -73,7 +78,10 @@ impl Handle {
///
/// [`Handle`]: struct.Handle.html
pub fn try_clone(&self) -> Result<Self, Error> {
self.inner.try_clone_hotfix().map(Self::from_file_unchecked)
self.inner
.try_clone_hotfix()
.map(Self::from_file_unchecked)
.wrap("clone underlying handle file")
}

/// Unwrap a [`Handle`] to reveal the underlying [`File`].
Expand Down
7 changes: 6 additions & 1 deletion src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ impl Root {
/// [`Root`]: struct.Root.html
pub fn try_clone(&self) -> Result<Self, Error> {
Ok(Self {
inner: self.inner.try_clone_hotfix()?,
inner: self
.as_file()
.try_clone_hotfix()
.wrap("clone underlying root file")?,
resolver: self.resolver,
})
}
Expand Down Expand Up @@ -250,6 +253,8 @@ impl Root {
self.resolver.resolve(&self.inner, path)
}

// TODO: readlink (need to move ResolverFlags out of Resolver)

/// Within the [`Root`]'s tree, create an inode at `path` as specified by
/// `inode_type`.
///
Expand Down

0 comments on commit 8cb1ddf

Please sign in to comment.