1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

feat(checksum): add doc

This commit is contained in:
Dorian Péron 2024-10-25 13:24:43 +02:00 committed by Sylvestre Ledru
parent 5309b65867
commit a09c7cc0d2

View file

@ -75,13 +75,22 @@ struct ChecksumResult {
pub failed_open_file: i32, pub failed_open_file: i32,
} }
/// Represents a reason for which the processing of a checksum line
/// could not proceed to digest comparison.
enum LineCheckError { enum LineCheckError {
/// a generic UError was encountered in sub-functions
UError(Box<dyn UError>), UError(Box<dyn UError>),
/// the computed checksum digest differs from the expected one
DigestMismatch, DigestMismatch,
/// the line is empty or is a comment
Skipped, Skipped,
/// the line has a formatting error
ImproperlyFormatted, ImproperlyFormatted,
/// file exists but is impossible to read
CantOpenFile, CantOpenFile,
/// there is nothing at the given path
FileNotFound, FileNotFound,
/// the given path leads to a directory
FileIsDirectory, FileIsDirectory,
} }
@ -97,10 +106,14 @@ impl From<ChecksumError> for LineCheckError {
} }
} }
/// Represents an error that was encountered when processing a checksum file.
#[allow(clippy::enum_variant_names)] #[allow(clippy::enum_variant_names)]
enum FileCheckError { enum FileCheckError {
/// a generic UError was encountered in sub-functions
UError(Box<dyn UError>), UError(Box<dyn UError>),
/// the error does not stop the processing of next files
NonCriticalError, NonCriticalError,
/// the error must stop the run of the program
CriticalError, CriticalError,
} }
@ -226,6 +239,8 @@ fn cksum_output(res: &ChecksumResult, status: bool) {
} }
} }
/// Represents the different outcomes that can happen to a file
/// that is being checked.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
enum FileChecksumResult { enum FileChecksumResult {
Ok, Ok,
@ -234,6 +249,8 @@ enum FileChecksumResult {
} }
impl FileChecksumResult { impl FileChecksumResult {
/// Creates a `FileChecksumResult` from a digest comparison that
/// either succeeded or failed.
fn from_bool(checksum_correct: bool) -> Self { fn from_bool(checksum_correct: bool) -> Self {
if checksum_correct { if checksum_correct {
FileChecksumResult::Ok FileChecksumResult::Ok
@ -242,6 +259,8 @@ impl FileChecksumResult {
} }
} }
/// The cli options might prevent to display on the outcome of the
/// comparison on STDOUT.
fn can_display(&self, opts: ChecksumOptions) -> bool { fn can_display(&self, opts: ChecksumOptions) -> bool {
match self { match self {
FileChecksumResult::Ok => !opts.status && !opts.quiet, FileChecksumResult::Ok => !opts.status && !opts.quiet,