Skip to content

Commit

Permalink
tree-wide: Add Debug impls
Browse files Browse the repository at this point in the history
I find this really useful as a general baseline; I'm a
"printf debugger" person by default. Add derives tree wide (plus two
manual impls). Enable deny-by-default lint.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters authored and allisonkarlitskaya committed Dec 9, 2024
1 parent 47f9fc8 commit 873b82d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub fn write_to_path(repo: &Repository, dir: &Directory, output_dir: &Path) -> R
write_directory_contents(dir, &fd, repo)
}

#[derive(Debug)]
pub struct FilesystemReader<'repo> {
repo: Option<&'repo Repository>,
inodes: HashMap<(u64, u64), Rc<Leaf>>,
Expand Down
2 changes: 2 additions & 0 deletions src/fsverity/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::Sha256HashValue;

// TODO: support Sha512

#[derive(Debug)]
struct FsVerityLayer {
context: Sha256,
remaining: usize,
Expand All @@ -31,6 +32,7 @@ impl FsVerityLayer {
}
}

#[derive(Debug)]
pub struct FsVerityHasher {
layers: Vec<FsVerityLayer>,
value: Option<Sha256HashValue>,
Expand Down
2 changes: 2 additions & 0 deletions src/fsverity/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum MeasureVerityError {

// See /usr/include/linux/fsverity.h
#[repr(C)]
#[derive(Debug)]
pub struct FsVerityEnableArg {
version: u32,
hash_algorithm: u32,
Expand Down Expand Up @@ -60,6 +61,7 @@ pub fn fs_ioc_enable_verity<F: AsFd, H: FsVerityHashValue>(fd: F) -> std::io::Re

/// Core definition of a fsverity digest.
#[repr(C)]
#[derive(Debug)]
pub struct FsVerityDigest<F> {
digest_algorithm: u16,
digest_size: u16,
Expand Down
1 change: 1 addition & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl Directory {
}
}

#[derive(Debug)]
pub struct FileSystem {
pub root: Directory,
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(missing_debug_implementations)]

pub mod dumpfile;
pub mod dumpfile_parse;
pub mod fs;
Expand Down
1 change: 1 addition & 0 deletions src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub fn pivot_sysroot(image: impl AsFd, basedir: &Path, sysroot: &Path) -> Result
}
}

#[derive(Debug)]
pub struct MountOptions<'a> {
image: &'a str,
basedir: &'a Path,
Expand Down
1 change: 1 addition & 0 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
util::{parse_sha256, proc_self_fd},
};

#[derive(Debug)]
pub struct Repository {
repository: OwnedFd,
path: PathBuf,
Expand Down
24 changes: 24 additions & 0 deletions src/splitstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ use crate::{
util::read_exactish,
};

#[derive(Debug)]
pub struct DigestMapEntry {
pub body: Sha256HashValue,
pub verity: Sha256HashValue,
}

#[derive(Debug)]
pub struct DigestMap {
pub map: Vec<DigestMapEntry>,
}
Expand Down Expand Up @@ -63,6 +65,17 @@ pub struct SplitStreamWriter<'a> {
pub sha256: Option<(Sha256, Sha256HashValue)>,
}

impl std::fmt::Debug for SplitStreamWriter<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// writer doesn't impl Debug
f.debug_struct("SplitStreamWriter")
.field("repo", &self.repo)
.field("inline_content", &self.inline_content)
.field("sha256", &self.sha256)
.finish()
}
}

impl SplitStreamWriter<'_> {
pub fn new(
repo: &Repository,
Expand Down Expand Up @@ -153,6 +166,7 @@ impl SplitStreamWriter<'_> {
}
}

#[derive(Debug)]
pub enum SplitStreamData {
Inline(Vec<u8>),
External(Sha256HashValue),
Expand All @@ -165,6 +179,16 @@ pub struct SplitStreamReader<R: Read> {
inline_bytes: usize,
}

impl<R: Read> std::fmt::Debug for SplitStreamReader<R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// decoder doesn't impl Debug
f.debug_struct("SplitStreamReader")
.field("refs", &self.refs)
.field("inline_bytes", &self.inline_bytes)
.finish()
}
}

fn read_u64_le<R: Read>(reader: &mut R) -> Result<Option<usize>> {
let mut buf = [0u8; 8];
if read_exactish(reader, &mut buf)? {
Expand Down

0 comments on commit 873b82d

Please sign in to comment.