Skip to content

Commit

Permalink
fix(devinfo): use MountIter<BufReader<R>>::new_from_readable with Mou…
Browse files Browse the repository at this point in the history
…ntIter<BufReader<File>>

Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Feb 14, 2024
1 parent d46dd34 commit 00bc4b7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions devinfo/src/mountinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ pub struct MountIter<R> {
}

impl<R: io::Read> MountIter<BufReader<R>> {
/// Read mounts from any mount-tab-like file.
pub fn new_from_readable(readable: R) -> io::Result<Self> {
Ok(Self::new_from_reader(BufReader::new(readable)))
/// Read mounts from any file/buffer, or anything which implements
/// std::io::Read or event Box<dyn std::io::Read>.
pub fn new_from_readable(readable: R) -> Self {
Self::new_from_reader(BufReader::new(readable))
}
}

Expand All @@ -165,7 +166,7 @@ impl MountIter<BufReader<File>> {

/// Read mounts from any mount-tab-like file.
pub fn new_from_file<P: AsRef<Path>>(path: P) -> io::Result<Self> {
Ok(Self::new_from_reader(BufReader::new(File::open(path)?)))
Ok(Self::new_from_readable(File::open(path)?))
}
}

Expand Down Expand Up @@ -284,11 +285,11 @@ impl SafeMountIter {
let buf: ByteBuf =
consistent_read(safe_mount_iter.mounts_filepath.as_path(), retries)?.into();
let buf: Box<dyn io::Read> = Box::new(buf);
return Ok(MountIter::new_from_readable(buf)?);
return Ok(MountIter::new_from_readable(buf));
}

let file = File::open(safe_mount_iter.mounts_filepath.as_path())?;
let file: Box<dyn io::Read> = Box::new(file);
Ok(MountIter::new_from_readable(file)?)
Ok(MountIter::new_from_readable(file))
}
}

0 comments on commit 00bc4b7

Please sign in to comment.