Skip to content

Commit

Permalink
WIP: refactor allLayersCached
Browse files Browse the repository at this point in the history
  • Loading branch information
emmileaf committed Sep 2, 2022
1 parent c9a51ec commit 755dcfc
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,27 @@ static void verifyImageMetadata(ImageMetadataTemplate metadata, Path metadataCac
*/
boolean allLayersCached(ManifestTemplate manifest) {

if (manifest instanceof V21ManifestTemplate) {
for (DescriptorDigest layerDigest : ((V21ManifestTemplate) manifest).getLayerDigests()) {
Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);
if (!Files.exists(layerDirectory)) {
return false;
}
}
return true;
List<DescriptorDigest> layerDigests;

if (manifest instanceof V21ManifestTemplate) {
layerDigests = ((V21ManifestTemplate) manifest).getLayerDigests();
} else if (manifest instanceof BuildableManifestTemplate) {
for (BuildableManifestTemplate.ContentDescriptorTemplate layerTemplate :
((BuildableManifestTemplate) manifest).getLayers()) {
DescriptorDigest layerDigest = layerTemplate.getDigest();
if (layerDigest == null) {
return false;
}
Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);
if (!Files.exists(layerDirectory)) {
return false;
}
}
return true;
layerDigests =
((BuildableManifestTemplate) manifest)
.getLayers().stream()
.map(BuildableManifestTemplate.ContentDescriptorTemplate::getDigest)
.collect(Collectors.toList());
} else {
throw new IllegalArgumentException("Unknown manifest type: " + manifest);
}

for (DescriptorDigest layerDigest : layerDigests) {
Path layerDirectory = cacheStorageFiles.getLayerDirectory(layerDigest);
if (!Files.exists(layerDirectory)) {
return false;
}
}
return true;
}

/**
Expand Down

0 comments on commit 755dcfc

Please sign in to comment.