Also support the generation-less legacy naming scheme

This commit is contained in:
Arpad Müller
2024-06-07 22:12:04 +02:00
parent e6a0e7ec61
commit 2eb8b428cc
2 changed files with 31 additions and 25 deletions

View File

@@ -312,17 +312,24 @@ pub(crate) async fn main(cmd: &LayerCmd) -> Result<()> {
let Some(file_name) = file_key.object_name() else {
continue;
};
// Split off the final part. Sometimes this cuts off actually important pieces in case of legacy layer files, but usually it doesn't.
let Some(file_without_generation) = file_name.rsplit_once('-') else {
continue;
};
let Ok(LayerName::Image(_layer_file_name)) =
LayerName::from_str(file_without_generation.0)
else {
// Skipping because it's either not a layer or an image layer
//println!("object {file_name}: not an image layer");
continue;
};
match LayerName::from_str(file_name) {
Ok(LayerName::Delta(_)) => continue,
Ok(LayerName::Image(_)) => (),
Err(_e) => {
// Split off the final part. We ensured above that this is not turning a
// generation-less delta layer file name into an image layer file name.
let Some(file_without_generation) = file_name.rsplit_once('-') else {
continue;
};
let Ok(LayerName::Image(_layer_file_name)) =
LayerName::from_str(file_without_generation.0)
else {
// Skipping because it's either not a layer or an image layer
//println!("object {file_name}: not an image layer");
continue;
};
}
}
let json_file_path = layers_dir.join(format!("{file_name}.json"));
if tokio::fs::try_exists(&json_file_path).await? {
//println!("object {file_name}: report already created");

View File

@@ -269,20 +269,19 @@ impl<const BUFFERED: bool> BlobWriter<BUFFERED> {
use ImageCompressionAlgorithm::*;
let (high_bit_mask, len_written, srcbuf) = match algorithm {
Some(ZstdLow | Zstd | ZstdHigh) => {
let mut encoder =
if matches!(algorithm, Some(ZstdLow)) {
async_compression::tokio::write::ZstdEncoder::with_quality(
Vec::new(),
Level::Precise(1),
)
} else if matches!(algorithm, Some(ZstdHigh)) {
async_compression::tokio::write::ZstdEncoder::with_quality(
Vec::new(),
Level::Precise(6),
)
} else {
async_compression::tokio::write::ZstdEncoder::new(Vec::new())
};
let mut encoder = if matches!(algorithm, Some(ZstdLow)) {
async_compression::tokio::write::ZstdEncoder::with_quality(
Vec::new(),
Level::Precise(1),
)
} else if matches!(algorithm, Some(ZstdHigh)) {
async_compression::tokio::write::ZstdEncoder::with_quality(
Vec::new(),
Level::Precise(6),
)
} else {
async_compression::tokio::write::ZstdEncoder::new(Vec::new())
};
let slice = srcbuf.slice(..);
encoder.write_all(&slice[..]).await.unwrap();
encoder.flush().await.unwrap();