Skip to content

feat: detect checksum files based on file extensions #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025

Conversation

Integral-Tech
Copy link
Contributor

Summary

Detect checksum files based on suffixes.

Closes: #181

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • This change requires a documentation update

Test plan

todo

@Integral-Tech Integral-Tech force-pushed the add-checksum-suffix branch 2 times, most recently from ee14288 to 020f69a Compare May 26, 2025 04:48
@ifd3f ifd3f self-assigned this May 27, 2025
@ifd3f
Copy link
Owner

ifd3f commented May 27, 2025

Just wondering, haven't looked much into this PR yet, will this conflict with #184?

@dbohdan
Copy link
Contributor

dbohdan commented May 27, 2025

#184 makes minimum changes to find_hash besides renaming it, so this PR should be easy to rebase.

Copy link
Owner

@ifd3f ifd3f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran it locally and it looks good.

% cargo run -- burn duo256_sd.img
   Compiling caligula v0.4.8 (/home/astrid/Documents/caligula)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.33s
     Running `target/debug/caligula burn duo256_sd.img`
Input file: duo256_sd.img
Detected compression format: no compression
> Is this okay? Yes
> Detected hash file duo256_sd.img.sha256 in the directory. Do you want to use it? Yes
Disk image verified successfully!
? Select target disk  
> <Refresh devices>
  <Show all disks, removable or not>
[Only displaying removable disks.]

I like the feature, but I'd prefer if you just made a separate array for extensions, and separated out the logic accordingly. Something like this:

const HASH_FILES: &[(HashAlg, &str)] = &[
    (HashAlg::Md5, "md5sum.txt"),
    (HashAlg::Md5, "md5sums.txt"),
    (HashAlg::Md5, "MD5SUM"),
    ...
];

const HASH_EXTENSIONS: &[(HashAlg, &str)] = &[
    (HashAlg::Md5, "md5"),
    (HashAlg::Sha1, "sha1"),
    ...
];

pub fn find_hash(input: &Path) -> Option<(HashAlg, String, Vec<u8>)> {
    for (alg, hash_file) in HASH_FILES {
        ...
    }
    for (alg, hash_file) in HASH_EXTENSIONS {
        ...
    }
}

@Integral-Tech Integral-Tech force-pushed the add-checksum-suffix branch from 020f69a to 9277f7b Compare May 28, 2025 12:17
@Integral-Tech Integral-Tech changed the title feat: detect checksum files based on suffixes feat: detect checksum files based on file extensions May 28, 2025
@Integral-Tech Integral-Tech requested a review from ifd3f May 28, 2025 12:19
@Integral-Tech
Copy link
Contributor Author

@ifd3f Resolved :)

@ifd3f
Copy link
Owner

ifd3f commented May 28, 2025

Thanks! Will go merge and resolve conflicts when I get the chance.

Detect checksum files based on file extensions.

Closes: ifd3f#181
@Integral-Tech Integral-Tech force-pushed the add-checksum-suffix branch from 9277f7b to 035477a Compare May 29, 2025 02:31
@Integral-Tech
Copy link
Contributor Author

@ifd3f Conflicts resolved :)

@ifd3f ifd3f merged commit 6be4386 into ifd3f:main May 29, 2025
24 checks passed
@Integral-Tech Integral-Tech deleted the add-checksum-suffix branch May 29, 2025 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect checksum files (.md5, .sha256, etc.)
3 participants