-
Notifications
You must be signed in to change notification settings - Fork 52
feat(dfget): add support for digest-manifest (#1561) #1570
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
base: main
Are you sure you want to change the base?
Conversation
gaius-qi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix lint.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1570 +/- ##
==========================================
+ Coverage 42.89% 44.56% +1.67%
==========================================
Files 75 75
Lines 21159 21241 +82
==========================================
+ Hits 9077 9467 +390
+ Misses 12082 11774 -308
🚀 New features to boost your workflow:
|
45b9e8c to
d6d2560
Compare
done. |
| let mut digests = HashMap::new(); | ||
| let mut line_num = 0; | ||
|
|
||
| for line in content.lines() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (line_num, line) in content.lines().enumerate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| // Parse line: <algorithm>:<digest> <filepath> | ||
| let parts: Vec<&str> = line.split_whitespace().collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.split_once(char::is_whitespace)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| // Remove trailing '/' from URL if present | ||
| let mut base_url = url.to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let base_url = url.as_str().trim_end_matches('/');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| ) -> Result<()> { | ||
| for entry in file_entries { | ||
| // Check if the entry URL exists in digests hashmap using exact match | ||
| if digests.get(&entry.url).is_none() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains_key()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| // Remove trailing '/' from URL if present | ||
| let base_url = url.as_str().trim_end_matches('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the 'base_url' out of the loop to improve performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| // Parse line: <algorithm>:<digest> <filepath> | ||
| let (digest_part, filepath_part) = match line.split_once(char::is_whitespace) { | ||
| Some((digest, filepath)) if !filepath.trim().is_empty() => (digest, filepath), | ||
| Some(_) | None => { | ||
| return Err(Error::DigestManifestParseFailed { | ||
| filepath: manifest_path.to_string_lossy().to_string(), | ||
| error: format!( | ||
| "invalid digest manifest format at line {}: expected '<algorithm>:<digest> <filepath>'", | ||
| line_num | ||
| ), | ||
| }); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Parse line: <algorithm>:<digest> <filepath> | |
| let (digest_part, filepath_part) = match line.split_once(char::is_whitespace) { | |
| Some((digest, filepath)) if !filepath.trim().is_empty() => (digest, filepath), | |
| Some(_) | None => { | |
| return Err(Error::DigestManifestParseFailed { | |
| filepath: manifest_path.to_string_lossy().to_string(), | |
| error: format!( | |
| "invalid digest manifest format at line {}: expected '<algorithm>:<digest> <filepath>'", | |
| line_num | |
| ), | |
| }); | |
| } | |
| }; | |
| // Parse line: <algorithm>:<digest> <filepath> | |
| // Use `split_once` for cleaner parsing logic and clearer error handling. | |
| let (digest_part, filepath_part) = line.split_once(char::is_whitespace) | |
| .filter(|(_, fp)| !fp.trim().is_empty()) | |
| .ok_or_else(|| Error::DigestManifestParseFailed { | |
| filepath: manifest_path.to_string_lossy().to_string(), | |
| error: format!( | |
| "invalid digest manifest format at line {}: expected '<algorithm>:<digest> <filepath>'", | |
| display_line_num | |
| ), | |
| })?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid duplicated match sentences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| format!("{}/{}", base_url, filepath) | ||
| }; | ||
|
|
||
| digests.insert(key, digest_part.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest avoiding the duplicate item before returning the parsed data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: pirDOL <pirdol@qq.com>
Description
feat(dfget): add support for digest-manifest
Related Issue
#1561
Screenshots (if appropriate)