Skip to content

Commit

Permalink
Move write_layer to shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
Malax committed Apr 9, 2024
1 parent c2a7f62 commit ec1b41a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
11 changes: 7 additions & 4 deletions libcnb/src/layer/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ pub enum ReadLayerError {
IoError(#[from] std::io::Error),
}

/// Updates layer metadata on disk
pub(in crate::layer) fn write_layer<M: Serialize, P: AsRef<Path>>(
layers_dir: P,
layer_name: &LayerName,
layer_content_metadata: &LayerContentMetadata<M>,
) -> Result<(), WriteLayerError> {
let layers_dir = layers_dir.as_ref();
fs::create_dir_all(layers_dir.join(layer_name.as_str()))?;
replace_layer_metadata(layers_dir, layer_name, layer_content_metadata)
let layer_dir = layers_dir.as_ref().join(layer_name.as_str());
fs::create_dir_all(layer_dir)?;

let layer_content_metadata_path = layers_dir.as_ref().join(format!("{layer_name}.toml"));

write_toml_file(&layer_content_metadata, layer_content_metadata_path)
.map_err(WriteLayerMetadataError::TomlFileError)
.map_err(WriteLayerError::WriteLayerMetadataError)?;

Ok(())
Expand Down
17 changes: 1 addition & 16 deletions libcnb/src/layer/trait_api/handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,6 @@ pub(in crate::layer) enum Sboms {
Replace(Vec<Sbom>),
}

pub(in crate::layer) fn write_layer_metadata<M: Serialize, P: AsRef<Path>>(
layers_dir: P,
layer_name: &LayerName,
layer_content_metadata: &LayerContentMetadata<M>,
) -> Result<(), WriteLayerMetadataError> {
let layer_dir = layers_dir.as_ref().join(layer_name.as_str());
fs::create_dir_all(layer_dir)?;

let layer_content_metadata_path = layers_dir.as_ref().join(format!("{layer_name}.toml"));
write_toml_file(&layer_content_metadata, layer_content_metadata_path)?;

Ok(())
}

/// Updates layer metadata on disk
pub(in crate::layer) fn write_layer<M: Serialize, P: AsRef<Path>>(
layers_dir: P,
Expand All @@ -237,8 +223,7 @@ pub(in crate::layer) fn write_layer<M: Serialize, P: AsRef<Path>>(
) -> Result<(), WriteLayerError> {
let layers_dir = layers_dir.as_ref();

write_layer_metadata(layers_dir, layer_name, layer_content_metadata)
.map_err(WriteLayerError::WriteLayerMetadataError)?;
crate::layer::shared::write_layer(layers_dir, layer_name, layer_content_metadata)?;

let layer_dir = layers_dir.join(layer_name.as_str());
layer_env.write_to_layer_dir(layer_dir)?;
Expand Down

0 comments on commit ec1b41a

Please sign in to comment.