-
Notifications
You must be signed in to change notification settings - Fork 122
fix: Analyze and simply handle consistency issues between the database and S3. #1952
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
Changes from all commits
9dd6b27
4931ecb
d3268f1
6defe8e
263f647
4a511db
2803fa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,19 @@ pub const ZERO_ID: &str = match std::str::from_utf8(&[b'0'; 40]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Err(_) => panic!("can't get ZERO_ID"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Returns true if `oid` looks like a full Git object id in hex form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// We intentionally only accept full-hex ids here (no short ids), because short ids | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// require repository-specific disambiguation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Supported lengths: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// - SHA-1 : 40 hex chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// - SHA-256 : 64 hex chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn is_full_hex_object_id(oid: &str) -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let is_valid_len = oid.len() == 40 || oid.len() == 64; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is_valid_len && oid.as_bytes().iter().all(|b| b.is_ascii_hexdigit()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(test)] | |
| mod tests { | |
| use super::is_full_hex_object_id; | |
| #[test] | |
| fn full_sha1_hex_is_accepted() { | |
| // 40 hex characters | |
| let oid = "0123456789abcdef0123456789abcdef01234567"; | |
| assert_eq!(oid.len(), 40); | |
| assert!(is_full_hex_object_id(oid)); | |
| } | |
| #[test] | |
| fn full_sha256_hex_is_accepted() { | |
| // 64 hex characters | |
| let oid = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; | |
| assert_eq!(oid.len(), 64); | |
| assert!(is_full_hex_object_id(oid)); | |
| } | |
| #[test] | |
| fn invalid_lengths_are_rejected() { | |
| // 39, 41, 63, and 65 characters should all be rejected | |
| let too_short_sha1 = "0123456789abcdef0123456789abcdef0123456"; | |
| let too_long_sha1 = "0123456789abcdef0123456789abcdef012345678"; | |
| let too_short_sha256 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde"; | |
| let too_long_sha256 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0"; | |
| assert_eq!(too_short_sha1.len(), 39); | |
| assert_eq!(too_long_sha1.len(), 41); | |
| assert_eq!(too_short_sha256.len(), 63); | |
| assert_eq!(too_long_sha256.len(), 65); | |
| assert!(!is_full_hex_object_id(too_short_sha1)); | |
| assert!(!is_full_hex_object_id(too_long_sha1)); | |
| assert!(!is_full_hex_object_id(too_short_sha256)); | |
| assert!(!is_full_hex_object_id(too_long_sha256)); | |
| } | |
| #[test] | |
| fn non_hex_characters_are_rejected() { | |
| let with_g = "g123456789abcdef0123456789abcdef01234567"; | |
| let with_dash = "0123456789abcdef0123456789abcdef01234-67"; | |
| let with_z = "z123456789abcdef0123456789abcdef01234567"; | |
| assert!(!is_full_hex_object_id(with_g)); | |
| assert!(!is_full_hex_object_id(with_dash)); | |
| assert!(!is_full_hex_object_id(with_z)); | |
| } | |
| #[test] | |
| fn empty_string_is_rejected() { | |
| assert!(!is_full_hex_object_id("")); | |
| } | |
| #[test] | |
| fn_short_hashes_are_rejected() { | |
| let short7 = "abcdef0"; | |
| let short10 = "0123456789"; | |
| assert_eq!(short7.len(), 7); | |
| assert_eq!(short10.len(), 10); | |
| assert!(!is_full_hex_object_id(short7)); | |
| assert!(!is_full_hex_object_id(short10)); | |
| } | |
| } |
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.
Missing space after "///" in the comment. Should be "/// Object not found in underlying object storage (S3/GCS/local), but exists in the repository."