Skip to content

Commit

Permalink
feat(checksum): add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
RenjiSann authored and sylvestre committed Nov 16, 2024
1 parent 5309b65 commit a09c7cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/uucore/src/lib/features/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ struct ChecksumResult {
pub failed_open_file: i32,
}

/// Represents a reason for which the processing of a checksum line
/// could not proceed to digest comparison.
enum LineCheckError {
/// a generic UError was encountered in sub-functions
UError(Box<dyn UError>),
/// the computed checksum digest differs from the expected one
DigestMismatch,
/// the line is empty or is a comment
Skipped,
/// the line has a formatting error
ImproperlyFormatted,
/// file exists but is impossible to read
CantOpenFile,
/// there is nothing at the given path
FileNotFound,
/// the given path leads to a directory
FileIsDirectory,
}

Expand All @@ -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)]
enum FileCheckError {
/// a generic UError was encountered in sub-functions
UError(Box<dyn UError>),
/// the error does not stop the processing of next files
NonCriticalError,
/// the error must stop the run of the program
CriticalError,
}

Expand Down Expand Up @@ -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)]
enum FileChecksumResult {
Ok,
Expand All @@ -234,6 +249,8 @@ enum FileChecksumResult {
}

impl FileChecksumResult {
/// Creates a `FileChecksumResult` from a digest comparison that
/// either succeeded or failed.
fn from_bool(checksum_correct: bool) -> Self {
if checksum_correct {
FileChecksumResult::Ok
Expand All @@ -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 {
match self {
FileChecksumResult::Ok => !opts.status && !opts.quiet,
Expand Down

0 comments on commit a09c7cc

Please sign in to comment.