mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-21 11:56:38 +00:00
fix(s3): improve GitLab registry compatibility (#2596)
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -408,6 +408,24 @@ impl HashReader {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_calculated_checksum(&mut self, checksum_type: ChecksumType) -> Result<(), std::io::Error> {
|
||||
if !checksum_type.is_set() {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid checksum type"));
|
||||
}
|
||||
|
||||
let Some(hasher) = checksum_type.hasher() else {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "Invalid checksum type"));
|
||||
};
|
||||
|
||||
self.content_hash = Some(Checksum {
|
||||
checksum_type,
|
||||
..Default::default()
|
||||
});
|
||||
self.content_hasher = Some(hasher);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn checksum(&self) -> Option<Checksum> {
|
||||
if self
|
||||
.content_hash
|
||||
@@ -569,7 +587,13 @@ impl AsyncRead for HashReader {
|
||||
|
||||
let content_hash = hasher.finalize();
|
||||
|
||||
if content_hash != expected_content_hash.raw {
|
||||
if expected_content_hash.raw.is_empty()
|
||||
&& expected_content_hash.encoded.is_empty()
|
||||
&& !expected_content_hash.checksum_type.trailing()
|
||||
{
|
||||
expected_content_hash.raw = content_hash;
|
||||
expected_content_hash.encoded = general_purpose::STANDARD.encode(&expected_content_hash.raw);
|
||||
} else if content_hash != expected_content_hash.raw {
|
||||
let expected_hex = hex_simd::encode_to_string(&expected_content_hash.raw, hex_simd::AsciiCase::Lower);
|
||||
let actual_hex = hex_simd::encode_to_string(content_hash, hex_simd::AsciiCase::Lower);
|
||||
error!(
|
||||
@@ -742,6 +766,25 @@ mod tests {
|
||||
assert_eq!(buf, data);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_add_calculated_checksum_records_checksum() {
|
||||
let data = b"server-side copy checksum";
|
||||
let reader = BufReader::new(Cursor::new(&data[..]));
|
||||
let mut hash_reader = HashReader::from_stream(reader, data.len() as i64, data.len() as i64, None, None, false).unwrap();
|
||||
|
||||
hash_reader.add_calculated_checksum(ChecksumType::CRC64_NVME).unwrap();
|
||||
|
||||
let mut buf = Vec::new();
|
||||
hash_reader.read_to_end(&mut buf).await.unwrap();
|
||||
|
||||
let expected = Checksum::new_from_data(ChecksumType::CRC64_NVME, data).unwrap();
|
||||
let checksums = hash_reader.content_crc();
|
||||
|
||||
assert_eq!(buf, data);
|
||||
assert_eq!(hash_reader.content_crc_type(), Some(ChecksumType::CRC64_NVME));
|
||||
assert_eq!(checksums.get("CRC64NVME"), Some(&expected.encoded));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_hashreader_new_logic() {
|
||||
let data = b"test data";
|
||||
|
||||
Reference in New Issue
Block a user